Skip to content

Commit 3f32ec5

Browse files
authoredAug 6, 2024··
feat: TimePicker を追加 (#4821)
* feat: TimePicker を追加 * fix: FormControl に紐づくように修正 * fix: 強制カラーモードで余計な装飾が出ないように修正
1 parent fab5f5b commit 3f32ec5

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed
 

‎packages/smarthr-ui/src/components/FormControl/FormControl.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Select } from '../Select'
2121
import { StatusLabel } from '../StatusLabel'
2222
import { Text, TextProps } from '../Text'
2323
import { Textarea } from '../Textarea'
24+
import { TimePicker } from '../TimePicker'
2425
import { visuallyHiddenText } from '../VisuallyHiddenText/VisuallyHiddenText'
2526

2627
import type { Gap } from '../../types'
@@ -304,6 +305,7 @@ type InputComponent =
304305
| typeof CurrencyInput
305306
| typeof Textarea
306307
| typeof DatePicker
308+
| typeof TimePicker
307309
| typeof Select
308310
| typeof SingleComboBox
309311
| typeof MultiComboBox
@@ -327,6 +329,7 @@ const isInputElement = (
327329
type === CurrencyInput ||
328330
type === Textarea ||
329331
type === DatePicker ||
332+
type === TimePicker ||
330333
type === Select ||
331334
type === SingleComboBox ||
332335
type === MultiComboBox ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { StoryFn } from '@storybook/react/*'
2+
import React from 'react'
3+
4+
import { FormControl } from '../FormControl'
5+
6+
import { TimePicker } from './TimePicker'
7+
8+
export default {
9+
title: 'Forms(フォーム)/TimePicker',
10+
component: TimePicker,
11+
}
12+
13+
const _Template: StoryFn = (args) => (
14+
<FormControl title="時刻">
15+
<TimePicker {...args} />
16+
</FormControl>
17+
)
18+
19+
export const Default = _Template.bind({})
20+
21+
export const VRTFocus = _Template.bind({})
22+
VRTFocus.parameters = {
23+
controls: { hideNoControlsWarning: true },
24+
pseudo: {
25+
focusWithin: ['span:has(> input)'],
26+
},
27+
}
28+
29+
export const VRTForcedColors = _Template.bind({})
30+
VRTForcedColors.parameters = {
31+
chromatic: { forcedColors: 'active' },
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { ComponentPropsWithoutRef, forwardRef } from 'react'
2+
import { tv } from 'tailwind-variants'
3+
4+
type Props = ComponentPropsWithoutRef<'input'>
5+
6+
const timePicker = tv({
7+
slots: {
8+
wrapper: [
9+
'smarthr-ui-TimePicker',
10+
'shr-inline-block shr-border-shorthand shr-rounded-m shr-bg-white shr-px-0.5 shr-leading-none',
11+
'contrast-more:shr-border-high-contrast',
12+
'focus-within:shr-focus-indicator',
13+
],
14+
input:
15+
'shr-border-none shr-text-base shr-text-black shr-outline-none shr-outline-0 shr-p-[unset] shr-py-0.75 shr-h-[theme(fontSize.base)] shr-tabular-nums',
16+
},
17+
})
18+
19+
export const TimePicker: React.FC<Props> = forwardRef<HTMLInputElement, Props>(
20+
({ className, ...rest }, ref) => {
21+
const { wrapper, input } = timePicker()
22+
return (
23+
<span className={wrapper({ className })}>
24+
{/* eslint-disable-next-line smarthr/a11y-input-has-name-attribute, smarthr/a11y-input-in-form-control */}
25+
<input {...rest} ref={ref} type="time" className={input()} />
26+
</span>
27+
)
28+
},
29+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { TimePicker } from './TimePicker'

‎packages/smarthr-ui/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export * from './components/ResponseMessage'
104104
export * from './components/Badge'
105105
export * from './components/Switch'
106106
export * from './components/Stepper'
107+
export * from './components/TimePicker'
107108

108109
// layout components
109110
export { Center, Cluster, Reel, Stack, Sidebar } from './components/Layout'

0 commit comments

Comments
 (0)
Please sign in to comment.