diff --git a/packages/smarthr-ui/src/components/Button/AnchorButton.tsx b/packages/smarthr-ui/src/components/Button/AnchorButton.tsx index 51c6bf87ed..ae08ac1d7f 100644 --- a/packages/smarthr-ui/src/components/Button/AnchorButton.tsx +++ b/packages/smarthr-ui/src/components/Button/AnchorButton.tsx @@ -14,6 +14,7 @@ import { ElementRef, ElementRefProps } from '../../types' import { ButtonInner } from './ButtonInner' import { ButtonWrapper } from './ButtonWrapper' +import { DisabledDetail } from './DisabledDetail' import { BaseProps } from './types' type ElementProps = Omit< @@ -39,6 +40,7 @@ const AnchorButton = forwardRef( suffix, wide = false, variant = 'secondary', + disabledDetail, target, rel, elementAs, @@ -54,7 +56,7 @@ const AnchorButton = forwardRef( [rel, target], ) - return ( + const button = ( ) + + if (!props.href && disabledDetail) { + return + } + + return button }, ) diff --git a/packages/smarthr-ui/src/components/Button/Button.tsx b/packages/smarthr-ui/src/components/Button/Button.tsx index 1383e71b8d..fe90e7bf0d 100644 --- a/packages/smarthr-ui/src/components/Button/Button.tsx +++ b/packages/smarthr-ui/src/components/Button/Button.tsx @@ -3,13 +3,12 @@ import { tv } from 'tailwind-variants' import { usePortal } from '../../hooks/usePortal' import { DecoratorsType } from '../../types' -import { FaCircleInfoIcon } from '../Icon' import { Loader } from '../Loader' -import { Tooltip } from '../Tooltip' import { VisuallyHiddenText } from '../VisuallyHiddenText' import { ButtonInner } from './ButtonInner' import { ButtonWrapper } from './ButtonWrapper' +import { DisabledDetail } from './DisabledDetail' import { BaseProps } from './types' type ElementProps = Omit, keyof BaseProps> @@ -21,19 +20,6 @@ const buttonStyle = tv({ 'shr-align-bottom', '[&_.smarthr-ui-Loader-spinner]:shr-h-em [&_.smarthr-ui-Loader-spinner]:shr-w-em', ], - disabledWrapper: [ - 'smarthr-ui-Button-disabledWrapper', - 'shr-inline-flex shr-items-center shr-gap-0.25', - ], - disabledTooltip: [ - 'shr-overflow-y-visible', - /* Tooltip との距離を変えずに反応範囲を広げるために negative space を使う */ - '[&_.smarthr-ui-Icon]:-shr-m-0.25', - /* global styleなどでborder-boxが適用されている場合表示崩れを起こす為、content-boxを指定する */ - '[&_.smarthr-ui-Icon]:shr-box-content', - '[&_.smarthr-ui-Icon]:shr-p-0.25', - '[&_.smarthr-ui-Icon]:shr-text-grey', - ], }, variants: { isSecondary: { @@ -76,7 +62,7 @@ export const Button = forwardRef { - const { wrapper, loader: loaderSlot, disabledWrapper, disabledTooltip } = buttonStyle() + const { wrapper, loader: loaderSlot } = buttonStyle() const wrapperStyle = useMemo(() => wrapper({ className }), [className, wrapper]) const loaderStyle = useMemo( () => loaderSlot({ isSecondary: variant === 'secondary' }), @@ -119,22 +105,7 @@ export const Button = forwardRef - {button} - - - - - ) + return } return button diff --git a/packages/smarthr-ui/src/components/Button/DisabledDetail.tsx b/packages/smarthr-ui/src/components/Button/DisabledDetail.tsx new file mode 100644 index 0000000000..e06fbb279a --- /dev/null +++ b/packages/smarthr-ui/src/components/Button/DisabledDetail.tsx @@ -0,0 +1,51 @@ +import React, { type FC } from 'react' +import { tv } from 'tailwind-variants' + +import { FaCircleInfoIcon } from '../Icon' +import { Tooltip } from '../Tooltip' + +type DisabledDetailProps = { + button: React.JSX.Element + disabledDetail: { + icon?: React.FunctionComponent + message: React.ReactNode + } +} + +const disabledDetailStyle = tv({ + slots: { + disabledWrapper: [ + 'smarthr-ui-Button-disabledWrapper', + 'shr-inline-flex shr-items-center shr-gap-0.25', + ], + disabledTooltip: [ + 'shr-overflow-y-visible', + /* Tooltip との距離を変えずに反応範囲を広げるために negative space を使う */ + '[&_.smarthr-ui-Icon]:-shr-m-0.25', + /* global style��どでborder-boxが適用されている場合表示崩れを起こす為、content-boxを指定する */ + '[&_.smarthr-ui-Icon]:shr-box-content', + '[&_.smarthr-ui-Icon]:shr-p-0.25', + '[&_.smarthr-ui-Icon]:shr-text-grey', + ], + }, +}) + +export const DisabledDetail: FC = ({ button, disabledDetail }) => { + const { disabledWrapper, disabledTooltip } = disabledDetailStyle() + const DisabledDetailIcon = disabledDetail.icon ?? FaCircleInfoIcon + + return ( +
+ {button} + + + +
+ ) +} diff --git a/packages/smarthr-ui/src/components/Button/stories/AnchorButton.stories.tsx b/packages/smarthr-ui/src/components/Button/stories/AnchorButton.stories.tsx index e59172c388..2840f77d56 100644 --- a/packages/smarthr-ui/src/components/Button/stories/AnchorButton.stories.tsx +++ b/packages/smarthr-ui/src/components/Button/stories/AnchorButton.stories.tsx @@ -95,6 +95,14 @@ export const Disabled: StoryObj = { }, } +export const DisabledDetail: StoryObj = { + name: 'disabledDetail', + args: { + href: undefined, + disabledDetail: { message: 'ボタンが無効な理由' }, + }, +} + export const Square: StoryObj = { name: 'square', args: { diff --git a/packages/smarthr-ui/src/components/Button/stories/VRTAnchorButton.stories.tsx b/packages/smarthr-ui/src/components/Button/stories/VRTAnchorButton.stories.tsx index 87afce5881..18aafbf2fb 100644 --- a/packages/smarthr-ui/src/components/Button/stories/VRTAnchorButton.stories.tsx +++ b/packages/smarthr-ui/src/components/Button/stories/VRTAnchorButton.stories.tsx @@ -11,48 +11,126 @@ import type { StoryFn, StoryObj } from '@storybook/react' type Variant = ComponentProps['variant'] /** - * $ pict anchor-button.pixt.txt - * size disabled prefix suffix square wide - * s true なし なし false false - * default false あり なし false true - * default true なし あり false true - * s false なし なし true false - * default true なし なし true false - * s false なし あり false false - * s true あり なし false true - * s true あり なし false false + * $ pict anchor-button.txt + * size disabled disabledDetail prefix suffix square wide + * default true あり なし なし false false + * s false なし なし あり false true + * s true なし なし あり false false + * default false なし なし なし true false + * default true なし なし あり false true + * s true なし あり なし false true + * s true あり なし あり false false + * default true あり あり なし false false + * s true あり なし なし true false + * s false なし あり なし false false */ -const Template: StoryFn = (args) => ( - - {(['secondary', 'primary', 'danger', 'text', 'skeleton'] as Variant[]).map((variant) => ( - - - - ボタン - - } wide href="#"> - ボタン - - } wide> - ボタン - - - - - - - - } href="#"> - ボタン - - } wide> - ボタン - - }> - ボタン - - - +const _cases: Array> = [ + { + size: 'default', + href: undefined, + disabledDetail: { message: 'ボタンが無効な理由' }, + prefix: undefined, + suffix: undefined, + square: false, + wide: false, + }, + { + size: 's', + href: '#', + disabledDetail: undefined, + prefix: undefined, + suffix: , + square: false, + wide: true, + }, + { + size: 's', + href: undefined, + disabledDetail: undefined, + prefix: undefined, + suffix: , + square: false, + wide: false, + }, + { + size: 'default', + href: '#', + disabledDetail: undefined, + prefix: undefined, + suffix: undefined, + square: true, + wide: false, + }, + { + size: 'default', + href: undefined, + disabledDetail: undefined, + prefix: undefined, + suffix: , + square: false, + wide: true, + }, + { + size: 's', + href: undefined, + disabledDetail: undefined, + prefix: , + suffix: undefined, + square: false, + wide: true, + }, + { + size: 's', + href: undefined, + disabledDetail: { message: 'ボタンが無効な理由' }, + prefix: undefined, + suffix: , + square: false, + wide: false, + }, + { + size: 'default', + href: undefined, + disabledDetail: { message: 'ボタンが無効な理由' }, + prefix: , + suffix: undefined, + square: false, + wide: false, + }, + { + size: 's', + href: undefined, + disabledDetail: { message: 'ボタンが無効な理由' }, + prefix: undefined, + suffix: undefined, + square: true, + wide: false, + }, + { + size: 's', + href: '#', + disabledDetail: undefined, + prefix: , + suffix: undefined, + square: false, + wide: false, + }, +] + +const Template: StoryFn = (args) => ( + + {[undefined, 'hover', 'focus-visible'].map((id) => ( + + {(['secondary', 'primary', 'danger', 'text', 'skeleton'] as Variant[]).map((variant) => ( + + + {_cases.map((props, index) => ( + + ))} + + + ))} + ))} ) @@ -60,33 +138,21 @@ const Template: StoryFn = (args) => ( export default { title: 'Buttons(ボタン)/Button/AnchorButton/VRT', render: Template, - parameters: { - chromatic: { disableSnapshot: false }, + args: { + children: 'ボタン', }, - tags: ['!autodocs'], -} - -export const VRT = {} - -export const VRTHover = { - render: () => ( - <> -