Skip to content

Commit 00d7ac8

Browse files
AtsushiMclaude
andauthored
refactor(DropZone)!: decorators属性を削除しIntlProviderのみを使用 (#6236)
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 2c2bcb6 commit 00d7ac8

3 files changed

Lines changed: 20 additions & 24 deletions

File tree

packages/smarthr-ui/src/components/DropZone/DropZone.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ import {
1616
} from 'react'
1717
import { tv } from 'tailwind-variants'
1818

19-
import { useDecorators } from '../../hooks/useDecorators'
2019
import { useIntl } from '../../intl'
2120
import { Button } from '../Button'
2221
import { FaFolderOpenIcon } from '../Icon'
2322
import { VisuallyHiddenText } from '../VisuallyHiddenText'
2423

25-
import type { DecoratorsType } from '../../hooks/useDecorators'
26-
2724
const classNameGenerator = tv({
2825
slots: {
2926
wrapper: [
@@ -74,8 +71,8 @@ type AbstractProps = PropsWithChildren<{
7471
disabled?: boolean
7572
/** フォームにエラーがあるかどうか */
7673
error?: boolean
77-
/** コンポーネント内の文言を変更するための関数を設定 */
78-
decorators?: DecoratorsType<'selectButtonLabel'>
74+
/** ファイル選択ボタンのラベル */
75+
selectButtonLabel?: string
7976
}>
8077
type Props = AbstractProps & Omit<ComponentPropsWithRef<'div'>, keyof AbstractProps>
8178

@@ -85,7 +82,10 @@ const overrideEventDefault = (e: DragEvent<HTMLElement>) => {
8582
}
8683

8784
export const DropZone = forwardRef<HTMLInputElement, Props>(
88-
({ children, onSelectFiles, multiple = true, disabled, error, decorators, ...rest }, ref) => {
85+
(
86+
{ children, onSelectFiles, multiple = true, disabled, error, selectButtonLabel, ...rest },
87+
ref,
88+
) => {
8989
const fileRef = useRef<HTMLInputElement>(null)
9090
const [filesDraggedOver, setFilesDraggedOver] = useState(false)
9191
const classNames = useMemo(() => {
@@ -149,7 +149,7 @@ export const DropZone = forwardRef<HTMLInputElement, Props>(
149149
onClick={onClickButton}
150150
disabled={disabled}
151151
className={classNames.button}
152-
decorators={decorators}
152+
label={selectButtonLabel}
153153
/>
154154
<VisuallyHiddenText>
155155
{/* eslint-disable-next-line smarthr/a11y-input-in-form-control */}
@@ -171,25 +171,23 @@ export const DropZone = forwardRef<HTMLInputElement, Props>(
171171
)
172172

173173
const SelectButton = memo<
174-
ComponentPropsWithoutRef<typeof Button> & Pick<Props, 'decorators'> & { onClick: () => void }
175-
>(({ onClick, decorators, ...rest }) => {
174+
ComponentPropsWithoutRef<typeof Button> & { onClick: () => void; label?: string }
175+
>(({ onClick, label, ...rest }) => {
176176
const { localize } = useIntl()
177177

178-
const decoratorDefaultTexts = useMemo(
179-
() => ({
180-
selectButtonLabel: localize({
178+
const buttonLabel = useMemo(
179+
() =>
180+
label ||
181+
localize({
181182
id: 'smarthr-ui/DropZone/selectButtonLabel',
182183
defaultText: 'ファイルを選択',
183184
}),
184-
}),
185-
[localize],
185+
[label, localize],
186186
)
187187

188-
const decorated = useDecorators<'selectButtonLabel'>(decoratorDefaultTexts, decorators)
189-
190188
return (
191189
<Button {...rest} prefix={<FaFolderOpenIcon />} onClick={onClick}>
192-
{decorated.selectButtonLabel}
190+
{buttonLabel}
193191
</Button>
194192
)
195193
})

packages/smarthr-ui/src/components/DropZone/stories/DropZone.stories.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ export const Error: StoryObj<typeof DropZone> = {
5050
},
5151
}
5252

53-
export const Decorators: StoryObj<typeof DropZone> = {
54-
name: 'decorators',
53+
export const SelectButtonLabel: StoryObj<typeof DropZone> = {
54+
name: 'selectButtonLabel',
5555
args: {
56-
decorators: {
57-
selectButtonLabel: (txt) => `select file.(${txt})`,
58-
},
59-
children: 'ボタンのテキストを変更',
56+
selectButtonLabel: 'Choose File',
57+
children: 'カスタムラベルのボタン',
6058
},
6159
}

packages/smarthr-ui/src/components/DropZone/stories/VRTDropZone.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export default {
99
<Stack>
1010
<DropZone {...args} />
1111
<DropZone {...args}>children あり</DropZone>
12-
<DropZone {...args} decorators={{ selectButtonLabel: (txt) => `select file.(${txt})` }} />
1312
<DropZone {...args} disabled />
1413
<DropZone {...args} error />
14+
<DropZone {...args} selectButtonLabel="Choose File" />
1515
</Stack>
1616
),
1717
parameters: {

0 commit comments

Comments
 (0)