Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 月選択UI (MonthPicker) を追加したい #5030

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { StoryFn } from '@storybook/react/*'
import React from 'react'

import { FormControl } from '../FormControl'

import { MonthPicker } from './MonthPicker'

export default {
title: 'Forms(フォーム)/MonthPicker',
component: MonthPicker,
}

const _Template: StoryFn = (args) => (
<ul className="shr-list-none shr-space-y-1">
<li>
<FormControl title="月">
<MonthPicker {...args} name="month" />
</FormControl>
</li>
<li>
<FormControl title="非活性">
<MonthPicker {...args} disabled={true} name="disabled" />
</FormControl>
</li>
<li>
<FormControl title="エラーあり" autoBindErrorInput={false}>
<MonthPicker {...args} error={true} name="error" />
</FormControl>
</li>
<li>
<FormControl title="エラーあり with FormControl" errorMessages={['エラーメッセージ']}>
<MonthPicker {...args} name="error_With_formcontrol" />
</FormControl>
</li>
<li>
<FormControl title="読み取り専用">
<MonthPicker {...args} readOnly={true} name="read_only" />
</FormControl>
</li>
</ul>
)

export const Default = _Template.bind({})

export const VRTFocus = _Template.bind({})
VRTFocus.parameters = {
controls: { hideNoControlsWarning: true },
pseudo: {
focusWithin: ['span:has(> input)'],
},
}

export const VRTForcedColors = _Template.bind({})
VRTForcedColors.parameters = {
chromatic: { forcedColors: 'active' },
}
37 changes: 37 additions & 0 deletions packages/smarthr-ui/src/components/Picker/MonthPicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { forwardRef, useMemo } from 'react'

import { pickerStyle } from './style'
import { PickerProps } from './types'

type Props = {
/** フォームにエラーがあるかどうか */
error?: boolean
}

export const MonthPicker = forwardRef<HTMLInputElement, PickerProps<Props>>(
({ disabled, error, readOnly, className, ...rest }, ref) => {
const { wrapperStyle, innerStyle } = useMemo(() => {
const { wrapper, inner } = pickerStyle()
return {
wrapperStyle: wrapper({ className, disabled, readOnly }),
innerStyle: inner(),
}
}, [disabled, readOnly, className])

return (
<span className={wrapperStyle}>
{/* eslint-disable-next-line smarthr/a11y-input-in-form-control */}
<input
{...rest}
data-smarthr-ui-input="true"
ref={ref}
type="month"
disabled={disabled}
readOnly={readOnly}
aria-invalid={error || undefined}
className={innerStyle}
/>
</span>
)
},
)
37 changes: 37 additions & 0 deletions packages/smarthr-ui/src/components/Picker/TimePicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { forwardRef, useMemo } from 'react'

import { pickerStyle } from './style'
import { PickerProps } from './types'

type Props = {
/** フォームにエラーがあるかどうか */
error?: boolean
}

export const TimePicker = forwardRef<HTMLInputElement, PickerProps<Props>>(
({ disabled, error, readOnly, className, ...rest }, ref) => {
const { wrapperStyle, innerStyle } = useMemo(() => {
const { wrapper, inner } = pickerStyle()
return {
wrapperStyle: wrapper({ className, disabled, readOnly }),
innerStyle: inner(),
}
}, [disabled, readOnly, className])

return (
<span className={wrapperStyle}>
{/* eslint-disable-next-line smarthr/a11y-input-in-form-control */}
<input
{...rest}
data-smarthr-ui-input="true"
ref={ref}
type="time"
disabled={disabled}
readOnly={readOnly}
aria-invalid={error || undefined}
className={innerStyle}
/>
</span>
)
},
)
2 changes: 2 additions & 0 deletions packages/smarthr-ui/src/components/Picker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { TimePicker } from './TimePicker'
export { MonthPicker } from './MonthPicker'
28 changes: 28 additions & 0 deletions packages/smarthr-ui/src/components/Picker/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { tv } from 'tailwind-variants'

export const pickerStyle = tv({
slots: {
wrapper: [
'smarthr-ui-TimePicker',
'shr-inline-block shr-border-shorthand shr-rounded-m shr-bg-white shr-px-0.5 shr-leading-none',
'contrast-more:shr-border-high-contrast',
'focus-within:shr-focus-indicator',
'has-[[aria-invalid]]:shr-border-danger',
],
inner: [
'shr-border-none shr-text-base disabled:shr-text-disabled shr-bg-transparent shr-text-black shr-outline-none shr-outline-0 shr-p-[unset] shr-py-0.75 shr-h-[theme(fontSize.base)] shr-tabular-nums',
],
},
variants: {
disabled: {
true: {
wrapper: 'shr-pointer-events-none shr-bg-white-darken [&&&]:shr-border-default/50',
},
},
readOnly: {
true: {
wrapper: '[&&&]:shr-border-[theme(backgroundColor.background)] [&&&]:shr-bg-background',
},
},
},
})
3 changes: 3 additions & 0 deletions packages/smarthr-ui/src/components/Picker/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ComponentPropsWithoutRef } from 'react'

export type PickerProps<Props> = Props & Omit<ComponentPropsWithoutRef<'input'>, keyof Props>
63 changes: 0 additions & 63 deletions packages/smarthr-ui/src/components/TimePicker/TimePicker.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/smarthr-ui/src/components/TimePicker/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/smarthr-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export * from './components/ResponseMessage'
export * from './components/Badge'
export * from './components/Switch'
export * from './components/Stepper'
export * from './components/TimePicker'
export * from './components/Picker'

// layout components
export { Center, Cluster, Reel, Stack, Sidebar } from './components/Layout'
Expand Down
1 change: 1 addition & 0 deletions sandbox/next/e2e/rsc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SERVER_COMPONENTS = [
'HeaderLink',
'Icon',
'Loader',
'MonthPicker',
'RangeSeparator',
'ResponseMessage',
'SmartHRLogo',
Expand Down
10 changes: 10 additions & 0 deletions sandbox/next/src/app/rsc_test/MonthPicker/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { MonthPicker } from 'smarthr-ui'
export default function MonthPickerPage() {
return (
<>
<div>Success: MonthPicker</div>
<MonthPicker name="name" />
</>
)
}
Loading