smarthr-ui 100.0.0 → 100.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/lib/components/Checkbox/client/ActualCheckbox.cjs +8 -4
  2. package/lib/components/Checkbox/client/ActualCheckbox.cjs.map +1 -1
  3. package/lib/components/Checkbox/client/ActualCheckbox.js +8 -4
  4. package/lib/components/Checkbox/client/ActualCheckbox.js.map +1 -1
  5. package/lib/components/Dialog/ModelessDialog/ModelessDialog.cjs +2 -2
  6. package/lib/components/Dialog/ModelessDialog/ModelessDialog.cjs.map +1 -1
  7. package/lib/components/Dialog/ModelessDialog/ModelessDialog.js +2 -2
  8. package/lib/components/Dialog/ModelessDialog/ModelessDialog.js.map +1 -1
  9. package/lib/components/Dropdown/client/Dropdown.cjs +11 -5
  10. package/lib/components/Dropdown/client/Dropdown.cjs.map +1 -1
  11. package/lib/components/Dropdown/client/Dropdown.js +11 -5
  12. package/lib/components/Dropdown/client/Dropdown.js.map +1 -1
  13. package/lib/components/FloatArea/FloatArea.cjs +23 -22
  14. package/lib/components/FloatArea/FloatArea.cjs.map +1 -1
  15. package/lib/components/FloatArea/FloatArea.js +23 -22
  16. package/lib/components/FloatArea/FloatArea.js.map +1 -1
  17. package/lib/components/RadioButtonPanel/RadioButtonPanel.cjs +6 -5
  18. package/lib/components/RadioButtonPanel/RadioButtonPanel.cjs.map +1 -1
  19. package/lib/components/RadioButtonPanel/RadioButtonPanel.js +6 -5
  20. package/lib/components/RadioButtonPanel/RadioButtonPanel.js.map +1 -1
  21. package/lib/components/SegmentedControl/client/SegmentedControl.cjs +15 -11
  22. package/lib/components/SegmentedControl/client/SegmentedControl.cjs.map +1 -1
  23. package/lib/components/SegmentedControl/client/SegmentedControl.d.ts +2 -0
  24. package/lib/components/SegmentedControl/client/SegmentedControl.js +15 -11
  25. package/lib/components/SegmentedControl/client/SegmentedControl.js.map +1 -1
  26. package/metadata.json +1 -1
  27. package/package.json +1 -1
  28. package/smarthr-ui.css +52 -0
@@ -15,28 +15,29 @@ const classNameGenerator = ce({
15
15
  base: 'smarthr-ui-FloatArea shr-sticky shr-z-fixed-menu -shr-mx-0.5',
16
16
  variants: {
17
17
  bottom: {
18
- 0: 'shr-bottom-0',
19
- 0.25: 'shr-bottom-0.25',
20
- 0.5: 'shr-bottom-0.5',
21
- 0.75: 'shr-bottom-0.75',
22
- 1: 'shr-bottom-1',
23
- 1.25: 'shr-bottom-1.25',
24
- 1.5: 'shr-bottom-1.5',
25
- 2: 'shr-bottom-2',
26
- 2.5: 'shr-bottom-2.5',
27
- 3: 'shr-bottom-3',
28
- 3.5: 'shr-bottom-3.5',
29
- 4: 'shr-bottom-4',
30
- 8: 'shr-bottom-8',
31
- X3S: 'shr-bottom-0.25',
32
- XXS: 'shr-bottom-0.5',
33
- XS: 'shr-bottom-1',
34
- S: 'shr-bottom-1.5',
35
- M: 'shr-bottom-2',
36
- L: 'shr-bottom-2.5',
37
- XL: 'shr-bottom-3',
38
- XXL: 'shr-bottom-3.5',
39
- X3L: 'shr-bottom-4',
18
+ // HINT: Stack直下でもmargin-bottomがリセットされないように詳細度を上げる
19
+ 0: 'shr-bottom-0 [&&]:shr-mb-0',
20
+ 0.25: 'shr-bottom-0.25 [&&]:shr-mb-0.25',
21
+ 0.5: 'shr-bottom-0.5 [&&]:shr-mb-0.5',
22
+ 0.75: 'shr-bottom-0.75 [&&]:shr-mb-0.75',
23
+ 1: 'shr-bottom-1 [&&]:shr-mb-1',
24
+ 1.25: 'shr-bottom-1.25 [&&]:shr-mb-1.25',
25
+ 1.5: 'shr-bottom-1.5 [&&]:shr-mb-1.5',
26
+ 2: 'shr-bottom-2 [&&]:shr-mb-2',
27
+ 2.5: 'shr-bottom-2.5 [&&]:shr-mb-2.5',
28
+ 3: 'shr-bottom-3 [&&]:shr-mb-3',
29
+ 3.5: 'shr-bottom-3.5 [&&]:shr-mb-3.5',
30
+ 4: 'shr-bottom-4 [&&]:shr-mb-4',
31
+ 8: 'shr-bottom-8 [&&]:shr-mb-8',
32
+ X3S: 'shr-bottom-0.25 [&&]:shr-mb-0.25',
33
+ XXS: 'shr-bottom-0.5 [&&]:shr-mb-0.5',
34
+ XS: 'shr-bottom-1 [&&]:shr-mb-1',
35
+ S: 'shr-bottom-1.5 [&&]:shr-mb-1.5',
36
+ M: 'shr-bottom-2 [&&]:shr-mb-2',
37
+ L: 'shr-bottom-2.5 [&&]:shr-mb-2.5',
38
+ XL: 'shr-bottom-3 [&&]:shr-mb-3',
39
+ XXL: 'shr-bottom-3.5 [&&]:shr-mb-3.5',
40
+ X3L: 'shr-bottom-4 [&&]:shr-mb-4',
40
41
  },
41
42
  },
42
43
  });
@@ -1 +1 @@
1
- {"version":3,"file":"FloatArea.js","sources":["../../../src/components/FloatArea/FloatArea.tsx"],"sourcesContent":["import { type FC, type ReactNode, useMemo } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { Cluster, Stack } from '../Layout'\nimport { Panel } from '../Panel'\nimport { ResponseMessage } from '../ResponseMessage'\n\nimport type { ResponseStatusWithoutProcessing } from '../../hooks/useResponseStatus'\nimport type { AbstractSize, CharRelativeSize } from '../../themes'\nimport type { SHRComponentPropsWithRef } from '../../types'\n\nconst classNameGenerator = tv({\n base: 'smarthr-ui-FloatArea shr-sticky shr-z-fixed-menu -shr-mx-0.5',\n variants: {\n bottom: {\n 0: 'shr-bottom-0',\n 0.25: 'shr-bottom-0.25',\n 0.5: 'shr-bottom-0.5',\n 0.75: 'shr-bottom-0.75',\n 1: 'shr-bottom-1',\n 1.25: 'shr-bottom-1.25',\n 1.5: 'shr-bottom-1.5',\n 2: 'shr-bottom-2',\n 2.5: 'shr-bottom-2.5',\n 3: 'shr-bottom-3',\n 3.5: 'shr-bottom-3.5',\n 4: 'shr-bottom-4',\n 8: 'shr-bottom-8',\n X3S: 'shr-bottom-0.25',\n XXS: 'shr-bottom-0.5',\n XS: 'shr-bottom-1',\n S: 'shr-bottom-1.5',\n M: 'shr-bottom-2',\n L: 'shr-bottom-2.5',\n XL: 'shr-bottom-3',\n XXL: 'shr-bottom-3.5',\n X3L: 'shr-bottom-4',\n } as { [key in CharRelativeSize | AbstractSize]: string },\n },\n})\n\ntype Props = SHRComponentPropsWithRef<\n 'div',\n {\n /** 表示する `Button` または `AnchorButton` コンポーネント */\n primaryButton: ReactNode\n /** 表示する `Button` または `AnchorButton` コンポーネント */\n secondaryButton?: ReactNode\n /** tertiary 領域に表示するボタン */\n tertiaryButton?: ReactNode\n /** 操作に対するフィードバックメッセージ */\n responseStatus?: ResponseStatusWithoutProcessing\n /** コンポーネントの下端から、包含ブロックの下端までの間隔(基準フォントサイズの相対値または抽象値) */\n bottom?: CharRelativeSize | AbstractSize\n /** コンポーネントの `z-index` 値 */\n zIndex?: number\n }\n>\n\nexport const FloatArea: FC<Props> = ({\n primaryButton,\n secondaryButton,\n tertiaryButton,\n responseStatus,\n bottom,\n zIndex,\n style,\n className,\n ...rest\n}) => {\n const actualClassName = useMemo(\n () => classNameGenerator({ bottom: bottom ?? 1.5, className }),\n [bottom, className],\n )\n\n return (\n <Panel {...rest} layer={3} padding={1} className={actualClassName} style={{ ...style, zIndex }}>\n <Stack gap={0.5}>\n <Cluster>\n {tertiaryButton}\n <Cluster gap={1} className=\"shr-ms-auto\">\n {secondaryButton}\n {primaryButton}\n </Cluster>\n </Cluster>\n {responseStatus && (\n <p className=\"shr-ms-auto\">\n <ResponseMessage status={responseStatus.status}>{responseStatus.text}</ResponseMessage>\n </p>\n )}\n </Stack>\n </Panel>\n )\n}\n"],"names":["tv","_jsx","_jsxs"],"mappings":";;;;;;;;;;;;;AAWA,MAAM,kBAAkB,GAAGA,EAAE,CAAC;AAC5B,IAAA,IAAI,EAAE,8DAA8D;AACpE,IAAA,QAAQ,EAAE;AACR,QAAA,MAAM,EAAE;AACN,YAAA,CAAC,EAAE,cAAc;AACjB,YAAA,IAAI,EAAE,iBAAiB;AACvB,YAAA,GAAG,EAAE,gBAAgB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AO,EAAA,EAAA,QAAA,EAAA,CACL,cAAc,EACfA,IAAA,CAAC,OAAO,EAAA,EAAC,GAAG,EAAE,CAAC,EAAE,SAAS,EAAC,aAAa,EAAA,QAAA,EAAA,CACrC,eAAe,EACf,aAAa,IACN,CAAA,EAAA,CACF,EACT,cAAc,KACbD,WAAG,SAAS,EAAC,aAAa,EAAA,QAAA,EACxBA,IAAC,eAAe,EAAA,EAAC,MAAM,EAAE,cAAc,CAAC,MAAM,EAAA,QAAA,EAAG,cAAc,CAAC,IAAI,EAAA,CAAmB,EAAA,CACrF,CACL,CAAA,EAAA,CACK,EAAA,CACF;AAEZ;;"}
1
+ {"version":3,"file":"FloatArea.js","sources":["../../../src/components/FloatArea/FloatArea.tsx"],"sourcesContent":["import { type FC, type ReactNode, useMemo } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { Cluster, Stack } from '../Layout'\nimport { Panel } from '../Panel'\nimport { ResponseMessage } from '../ResponseMessage'\n\nimport type { ResponseStatusWithoutProcessing } from '../../hooks/useResponseStatus'\nimport type { AbstractSize, CharRelativeSize } from '../../themes'\nimport type { SHRComponentPropsWithRef } from '../../types'\n\nconst classNameGenerator = tv({\n base: 'smarthr-ui-FloatArea shr-sticky shr-z-fixed-menu -shr-mx-0.5',\n variants: {\n bottom: {\n // HINT: Stack直下でもmargin-bottomがリセットされないように詳細度を上げる\n 0: 'shr-bottom-0 [&&]:shr-mb-0',\n 0.25: 'shr-bottom-0.25 [&&]:shr-mb-0.25',\n 0.5: 'shr-bottom-0.5 [&&]:shr-mb-0.5',\n 0.75: 'shr-bottom-0.75 [&&]:shr-mb-0.75',\n 1: 'shr-bottom-1 [&&]:shr-mb-1',\n 1.25: 'shr-bottom-1.25 [&&]:shr-mb-1.25',\n 1.5: 'shr-bottom-1.5 [&&]:shr-mb-1.5',\n 2: 'shr-bottom-2 [&&]:shr-mb-2',\n 2.5: 'shr-bottom-2.5 [&&]:shr-mb-2.5',\n 3: 'shr-bottom-3 [&&]:shr-mb-3',\n 3.5: 'shr-bottom-3.5 [&&]:shr-mb-3.5',\n 4: 'shr-bottom-4 [&&]:shr-mb-4',\n 8: 'shr-bottom-8 [&&]:shr-mb-8',\n X3S: 'shr-bottom-0.25 [&&]:shr-mb-0.25',\n XXS: 'shr-bottom-0.5 [&&]:shr-mb-0.5',\n XS: 'shr-bottom-1 [&&]:shr-mb-1',\n S: 'shr-bottom-1.5 [&&]:shr-mb-1.5',\n M: 'shr-bottom-2 [&&]:shr-mb-2',\n L: 'shr-bottom-2.5 [&&]:shr-mb-2.5',\n XL: 'shr-bottom-3 [&&]:shr-mb-3',\n XXL: 'shr-bottom-3.5 [&&]:shr-mb-3.5',\n X3L: 'shr-bottom-4 [&&]:shr-mb-4',\n } as { [key in CharRelativeSize | AbstractSize]: string },\n },\n})\n\ntype Props = SHRComponentPropsWithRef<\n 'div',\n {\n /** 表示する `Button` または `AnchorButton` コンポーネント */\n primaryButton: ReactNode\n /** 表示する `Button` または `AnchorButton` コンポーネント */\n secondaryButton?: ReactNode\n /** tertiary 領域に表示するボタン */\n tertiaryButton?: ReactNode\n /** 操作に対するフィードバックメッセージ */\n responseStatus?: ResponseStatusWithoutProcessing\n /** コンポーネントの下端から、包含ブロックの下端までの間隔(基準フォントサイズの相対値または抽象値) */\n bottom?: CharRelativeSize | AbstractSize\n /** コンポーネントの `z-index` 値 */\n zIndex?: number\n }\n>\n\nexport const FloatArea: FC<Props> = ({\n primaryButton,\n secondaryButton,\n tertiaryButton,\n responseStatus,\n bottom,\n zIndex,\n style,\n className,\n ...rest\n}) => {\n const actualClassName = useMemo(\n () => classNameGenerator({ bottom: bottom ?? 1.5, className }),\n [bottom, className],\n )\n\n return (\n <Panel {...rest} layer={3} padding={1} className={actualClassName} style={{ ...style, zIndex }}>\n <Stack gap={0.5}>\n <Cluster>\n {tertiaryButton}\n <Cluster gap={1} className=\"shr-ms-auto\">\n {secondaryButton}\n {primaryButton}\n </Cluster>\n </Cluster>\n {responseStatus && (\n <p className=\"shr-ms-auto\">\n <ResponseMessage status={responseStatus.status}>{responseStatus.text}</ResponseMessage>\n </p>\n )}\n </Stack>\n </Panel>\n )\n}\n"],"names":["tv","_jsx","_jsxs"],"mappings":";;;;;;;;;;;;;AAWA,MAAM,kBAAkB,GAAGA,EAAE,CAAC;AAC5B,IAAA,IAAI,EAAE,8DAA8D;AACpE,IAAA,QAAQ,EAAE;AACR,QAAA,MAAM,EAAE;;AAEN,YAAA,CAAC,EAAE,4BAA4B;AAC/B,YAAA,IAAI,EAAE,kCAAkC;AACxC,YAAA,GAAG,EAAE,gCAAgC;AACrC,YAAA,IAAI,EAAE,kCAAkC;AACxC,YAAA,CAAC,EAAE,4BAA4B;AAC/B,YAAA,IAAI,EAAE,kCAAkC;AACxC,YAAA,GAAG,EAAE,gCAAgC;AACrC,YAAA,CAAC,EAAE,4BAA4B;AAC/B,YAAA,GAAG,EAAE,gCAAgC;AACrC,YAAA,CAAC,EAAE,4BAA4B;AAC/B,YAAA,GAAG,EAAE,gCAAgC;AACrC,YAAA,CAAC,EAAE,4BAA4B;AAC/B,YAAA,CAAC,EAAE,4BAA4B;AAC/B,YAAA,GAAG,EAAE,kCAAkC;AACvC,YAAA,GAAG,EAAE,gCAAgC;AACrC,YAAA,EAAE,EAAE,4BAA4B;AAChC,YAAA,CAAC,EAAE,gCAAgC;AACnC,YAAA,CAAC,EAAE,4BAA4B;AAC/B,YAAA,CAAC,EAAE,gCAAgC;AACnC,YAAA,EAAE,EAAE,4BAA4B;AAChC,YAAA,GAAG,EAAE,gCAAgC;AACrC,YAAA,GAAG,EAAE,4BAA4B;AACsB,SAAA;AAC1D,KAAA;AACF,CAAA,CAAC;AAoBK,MAAM,SAAS,GAAc,CAAC,EACnC,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,MAAM,EACN,MAAM,EACN,KAAK,EACL,SAAS,EACT,GAAG,IAAI,EACR,KAAI;IACH,MAAM,eAAe,GAAG,OAAO,CAC7B,MAAM,kBAAkB,CAAC,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,EAAE,SAAS,EAAE,CAAC,EAC9D,CAAC,MAAM,EAAE,SAAS,CAAC,CACpB;AAED,IAAA,QACEC,GAAA,CAAC,KAAK,EAAA,EAAA,GAAK,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,EAAA,QAAA,EAC5FC,KAAC,KAAK,EAAA,EAAC,GAAG,EAAE,GAAG,EAAA,QAAA,EAAA,CACbA,IAAA,CAAC,OAAO,EAAA,EAAA,QAAA,EAAA,CACL,cAAc,EACfA,IAAA,CAAC,OAAO,EAAA,EAAC,GAAG,EAAE,CAAC,EAAE,SAAS,EAAC,aAAa,EAAA,QAAA,EAAA,CACrC,eAAe,EACf,aAAa,IACN,CAAA,EAAA,CACF,EACT,cAAc,KACbD,WAAG,SAAS,EAAC,aAAa,EAAA,QAAA,EACxBA,IAAC,eAAe,EAAA,EAAC,MAAM,EAAE,cAAc,CAAC,MAAM,EAAA,QAAA,EAAG,cAAc,CAAC,IAAI,EAAA,CAAmB,EAAA,CACrF,CACL,CAAA,EAAA,CACK,EAAA,CACF;AAEZ;;"}
@@ -35,11 +35,12 @@ const classNameGenerator = index.tv({
35
35
  const RadioButtonPanel = ({ children, className, ...rest }) => {
36
36
  const hasDescription = !!children;
37
37
  const classNames = React.useMemo(() => {
38
- const { base, description, radio } = classNameGenerator({
39
- className,
40
- hasDescription,
41
- });
42
- return { base: base(), description: description(), radio: radio() };
38
+ const { base, description, radio } = classNameGenerator();
39
+ return {
40
+ base: base({ className, hasDescription }),
41
+ description: description(),
42
+ radio: radio({ hasDescription }),
43
+ };
43
44
  }, [hasDescription, className]);
44
45
  return hasDescription ? (jsxRuntime.jsx(DescriptionRadioButtonPanel, { ...rest, classNames: classNames, children: children })) : (jsxRuntime.jsx(ActualRadioButtonPanel, { ...rest, classNames: classNames }));
45
46
  };
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButtonPanel.cjs","sources":["../../../src/components/RadioButtonPanel/RadioButtonPanel.tsx"],"sourcesContent":["import { type FC, type ReactNode, useId, useMemo } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { RadioButton } from '../RadioButton'\n\nimport { ClickablePanel } from './client'\n\nimport type { SHRComponentPropsWithRef } from '../../types'\n\ntype Props = SHRComponentPropsWithRef<\n typeof RadioButton,\n {\n label: ReactNode\n },\n { as: true }\n>\n\nconst classNameGenerator = tv({\n slots: {\n base: [\n 'smarthr-ui-RadioButtonPanel',\n 'shr-border-shorthand shr-cursor-pointer shr-list-none shr-shadow-none',\n 'has-[:disabled]:shr-cursor-default',\n // FIX: なぜか storybook 上で :has が動作しないので重ねて書いている\n 'has-[:focus-visible]:shr-focus-indicator [&:has(:focus-visible)]:shr-focus-indicator',\n '[&:has(:disabled)]:shr-text-disabled has-[:disabled]:[&_.smarthr-ui-RadioButtonPanel-description]:shr-text-disabled',\n ],\n radio: [\n '[&_.smarthr-ui-RadioButton-radioButton:focus-visible_+_span]:shr-focus-indicator-none',\n '[&_.smarthr-ui-RadioButton-label]:shr-ms-0.75',\n ],\n // RadioButtonPanel で指定している shr-ms-0.75 + RadioButton のボタンの shr-w-em を足して shr-ms-[1.75em] にしている\n description: ['smarthr-ui-RadioButtonPanel-description', 'shr-ms-[1.75em] shr-mt-0.5'],\n },\n variants: {\n hasDescription: {\n true: {\n base: 'shr-flex shr-flex-col',\n radio: 'shr-font-bold',\n },\n },\n },\n})\n\nexport const RadioButtonPanel: FC<Props> = ({ children, className, ...rest }) => {\n const hasDescription = !!children\n\n const classNames = useMemo(() => {\n const { base, description, radio } = classNameGenerator({\n className,\n hasDescription,\n })\n\n return { base: base(), description: description(), radio: radio() }\n }, [hasDescription, className])\n\n return hasDescription ? (\n <DescriptionRadioButtonPanel {...rest} classNames={classNames}>\n {children}\n </DescriptionRadioButtonPanel>\n ) : (\n <ActualRadioButtonPanel {...rest} classNames={classNames} />\n )\n}\n\ntype LowerProps = Omit<Props, 'className'> & {\n classNames: {\n base: string\n description: string\n radio: string\n }\n}\n\nconst DescriptionRadioButtonPanel: FC<LowerProps> = ({\n 'aria-describedby': ariaDescribedby,\n classNames,\n children,\n ...rest\n}) => {\n const descriptionId = useId()\n\n return (\n <ActualRadioButtonPanel\n {...rest}\n classNames={classNames}\n aria-describedby={`${descriptionId}${ariaDescribedby ? ` ${ariaDescribedby}` : ''}`}\n >\n <div id={descriptionId} className={classNames.description}>\n {children}\n </div>\n </ActualRadioButtonPanel>\n )\n}\n\nconst ActualRadioButtonPanel: FC<LowerProps> = ({ as, classNames, children, label, ...rest }) => (\n <ClickablePanel as={as} className={classNames.base}>\n <RadioButton {...rest} className={classNames.radio}>\n {label}\n </RadioButton>\n {children}\n </ClickablePanel>\n)\n"],"names":["tv","useMemo","_jsx","useId","_jsxs","ClickablePanel","RadioButton"],"mappings":";;;;;;;;AAiBA,MAAM,kBAAkB,GAAGA,QAAE,CAAC;AAC5B,IAAA,KAAK,EAAE;AACL,QAAA,IAAI,EAAE;YACJ,6BAA6B;YAC7B,uEAAuE;YACvE,oCAAoC;;YAEpC,sFAAsF;YACtF,qHAAqH;AACtH,SAAA;AACD,QAAA,KAAK,EAAE;YACL,uFAAuF;YACvF,+CAA+C;AAChD,SAAA;;AAED,QAAA,WAAW,EAAE,CAAC,yCAAyC,EAAE,4BAA4B,CAAC;AACvF,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE;AACJ,gBAAA,IAAI,EAAE,uBAAuB;AAC7B,gBAAA,KAAK,EAAE,eAAe;AACvB,aAAA;AACF,SAAA;AACF,KAAA;AACF,CAAA,CAAC;AAEK,MAAM,gBAAgB,GAAc,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,KAAI;AAC9E,IAAA,MAAM,cAAc,GAAG,CAAC,CAAC,QAA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,EAAE,SAAS,EAAE,UAAU,CAAC,IAAI,EAAA,QAAA,EAAA,CAChDH,cAAA,CAACI,8CAAW,EAAA,EAAA,GAAK,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,KAAK,EAAA,QAAA,EAC/C,KAAK,GACM,EACb,QAAQ,CAAA,EAAA,CACM,CAClB;;"}
1
+ {"version":3,"file":"RadioButtonPanel.cjs","sources":["../../../src/components/RadioButtonPanel/RadioButtonPanel.tsx"],"sourcesContent":["import { type FC, type ReactNode, useId, useMemo } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { RadioButton } from '../RadioButton'\n\nimport { ClickablePanel } from './client'\n\nimport type { SHRComponentPropsWithRef } from '../../types'\n\ntype Props = SHRComponentPropsWithRef<\n typeof RadioButton,\n {\n label: ReactNode\n },\n { as: true }\n>\n\nconst classNameGenerator = tv({\n slots: {\n base: [\n 'smarthr-ui-RadioButtonPanel',\n 'shr-border-shorthand shr-cursor-pointer shr-list-none shr-shadow-none',\n 'has-[:disabled]:shr-cursor-default',\n // FIX: なぜか storybook 上で :has が動作しないので重ねて書いている\n 'has-[:focus-visible]:shr-focus-indicator [&:has(:focus-visible)]:shr-focus-indicator',\n '[&:has(:disabled)]:shr-text-disabled has-[:disabled]:[&_.smarthr-ui-RadioButtonPanel-description]:shr-text-disabled',\n ],\n radio: [\n '[&_.smarthr-ui-RadioButton-radioButton:focus-visible_+_span]:shr-focus-indicator-none',\n '[&_.smarthr-ui-RadioButton-label]:shr-ms-0.75',\n ],\n // RadioButtonPanel で指定している shr-ms-0.75 + RadioButton のボタンの shr-w-em を足して shr-ms-[1.75em] にしている\n description: ['smarthr-ui-RadioButtonPanel-description', 'shr-ms-[1.75em] shr-mt-0.5'],\n },\n variants: {\n hasDescription: {\n true: {\n base: 'shr-flex shr-flex-col',\n radio: 'shr-font-bold',\n },\n },\n },\n})\n\nexport const RadioButtonPanel: FC<Props> = ({ children, className, ...rest }) => {\n const hasDescription = !!children\n\n const classNames = useMemo(() => {\n const { base, description, radio } = classNameGenerator()\n\n return {\n base: base({ className, hasDescription }),\n description: description(),\n radio: radio({ hasDescription }),\n }\n }, [hasDescription, className])\n\n return hasDescription ? (\n <DescriptionRadioButtonPanel {...rest} classNames={classNames}>\n {children}\n </DescriptionRadioButtonPanel>\n ) : (\n <ActualRadioButtonPanel {...rest} classNames={classNames} />\n )\n}\n\ntype LowerProps = Omit<Props, 'className'> & {\n classNames: {\n base: string\n description: string\n radio: string\n }\n}\n\nconst DescriptionRadioButtonPanel: FC<LowerProps> = ({\n 'aria-describedby': ariaDescribedby,\n classNames,\n children,\n ...rest\n}) => {\n const descriptionId = useId()\n\n return (\n <ActualRadioButtonPanel\n {...rest}\n classNames={classNames}\n aria-describedby={`${descriptionId}${ariaDescribedby ? ` ${ariaDescribedby}` : ''}`}\n >\n <div id={descriptionId} className={classNames.description}>\n {children}\n </div>\n </ActualRadioButtonPanel>\n )\n}\n\nconst ActualRadioButtonPanel: FC<LowerProps> = ({ as, classNames, children, label, ...rest }) => (\n <ClickablePanel as={as} className={classNames.base}>\n <RadioButton {...rest} className={classNames.radio}>\n {label}\n </RadioButton>\n {children}\n </ClickablePanel>\n)\n"],"names":["tv","useMemo","_jsx","useId","_jsxs","ClickablePanel","RadioButton"],"mappings":";;;;;;;;AAiBA,MAAM,kBAAkB,GAAGA,QAAE,CAAC;AAC5B,IAAA,KAAK,EAAE;AACL,QAAA,IAAI,EAAE;YACJ,6BAA6B;YAC7B,uEAAuE;YACvE,oCAAoC;;YAEpC,sFAAsF;YACtF,qHAAqH;AACtH,SAAA;AACD,QAAA,KAAK,EAAE;YACL,uFAAuF;YACvF,+CAA+C;AAChD,SAAA;;AAED,QAAA,WAAW,EAAE,CAAC,yCAAyC,EAAE,4BAA4B,CAAC;AACvF,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE;AACJ,gBAAA,IAAI,EAAE,uBAAuB;AAC7B,gBAAA,KAAK,EAA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A,EACtD,QAAQ,EAAA,CACL,EAAA,CACiB;AAE7B,CAAC;AAED,MAAM,sBAAsB,GAAmB,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,MAC1FE,eAAA,CAACC,gEAAc,EAAA,EAAC,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,IAAI,EAAA,QAAA,EAAA,CAChDH,cAAA,CAACI,8CAAW,EAAA,EAAA,GAAK,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,KAAK,EAAA,QAAA,EAC/C,KAAK,GACM,EACb,QAAQ,CAAA,EAAA,CACM,CAClB;;"}
@@ -33,11 +33,12 @@ const classNameGenerator = ce({
33
33
  const RadioButtonPanel = ({ children, className, ...rest }) => {
34
34
  const hasDescription = !!children;
35
35
  const classNames = useMemo(() => {
36
- const { base, description, radio } = classNameGenerator({
37
- className,
38
- hasDescription,
39
- });
40
- return { base: base(), description: description(), radio: radio() };
36
+ const { base, description, radio } = classNameGenerator();
37
+ return {
38
+ base: base({ className, hasDescription }),
39
+ description: description(),
40
+ radio: radio({ hasDescription }),
41
+ };
41
42
  }, [hasDescription, className]);
42
43
  return hasDescription ? (jsx(DescriptionRadioButtonPanel, { ...rest, classNames: classNames, children: children })) : (jsx(ActualRadioButtonPanel, { ...rest, classNames: classNames }));
43
44
  };
@@ -1 +1 @@
1
- {"version":3,"file":"RadioButtonPanel.js","sources":["../../../src/components/RadioButtonPanel/RadioButtonPanel.tsx"],"sourcesContent":["import { type FC, type ReactNode, useId, useMemo } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { RadioButton } from '../RadioButton'\n\nimport { ClickablePanel } from './client'\n\nimport type { SHRComponentPropsWithRef } from '../../types'\n\ntype Props = SHRComponentPropsWithRef<\n typeof RadioButton,\n {\n label: ReactNode\n },\n { as: true }\n>\n\nconst classNameGenerator = tv({\n slots: {\n base: [\n 'smarthr-ui-RadioButtonPanel',\n 'shr-border-shorthand shr-cursor-pointer shr-list-none shr-shadow-none',\n 'has-[:disabled]:shr-cursor-default',\n // FIX: なぜか storybook 上で :has が動作しないので重ねて書いている\n 'has-[:focus-visible]:shr-focus-indicator [&:has(:focus-visible)]:shr-focus-indicator',\n '[&:has(:disabled)]:shr-text-disabled has-[:disabled]:[&_.smarthr-ui-RadioButtonPanel-description]:shr-text-disabled',\n ],\n radio: [\n '[&_.smarthr-ui-RadioButton-radioButton:focus-visible_+_span]:shr-focus-indicator-none',\n '[&_.smarthr-ui-RadioButton-label]:shr-ms-0.75',\n ],\n // RadioButtonPanel で指定している shr-ms-0.75 + RadioButton のボタンの shr-w-em を足して shr-ms-[1.75em] にしている\n description: ['smarthr-ui-RadioButtonPanel-description', 'shr-ms-[1.75em] shr-mt-0.5'],\n },\n variants: {\n hasDescription: {\n true: {\n base: 'shr-flex shr-flex-col',\n radio: 'shr-font-bold',\n },\n },\n },\n})\n\nexport const RadioButtonPanel: FC<Props> = ({ children, className, ...rest }) => {\n const hasDescription = !!children\n\n const classNames = useMemo(() => {\n const { base, description, radio } = classNameGenerator({\n className,\n hasDescription,\n })\n\n return { base: base(), description: description(), radio: radio() }\n }, [hasDescription, className])\n\n return hasDescription ? (\n <DescriptionRadioButtonPanel {...rest} classNames={classNames}>\n {children}\n </DescriptionRadioButtonPanel>\n ) : (\n <ActualRadioButtonPanel {...rest} classNames={classNames} />\n )\n}\n\ntype LowerProps = Omit<Props, 'className'> & {\n classNames: {\n base: string\n description: string\n radio: string\n }\n}\n\nconst DescriptionRadioButtonPanel: FC<LowerProps> = ({\n 'aria-describedby': ariaDescribedby,\n classNames,\n children,\n ...rest\n}) => {\n const descriptionId = useId()\n\n return (\n <ActualRadioButtonPanel\n {...rest}\n classNames={classNames}\n aria-describedby={`${descriptionId}${ariaDescribedby ? ` ${ariaDescribedby}` : ''}`}\n >\n <div id={descriptionId} className={classNames.description}>\n {children}\n </div>\n </ActualRadioButtonPanel>\n )\n}\n\nconst ActualRadioButtonPanel: FC<LowerProps> = ({ as, classNames, children, label, ...rest }) => (\n <ClickablePanel as={as} className={classNames.base}>\n <RadioButton {...rest} className={classNames.radio}>\n {label}\n </RadioButton>\n {children}\n </ClickablePanel>\n)\n"],"names":["tv","_jsx","_jsxs"],"mappings":";;;;;;AAiBA,MAAM,kBAAkB,GAAGA,EAAE,CAAC;AAC5B,IAAA,KAAK,EAAE;AACL,QAAA,IAAI,EAAE;YACJ,6BAA6B;YAC7B,uEAAuE;YACvE,oCAAoC;;YAEpC,sFAAsF;YACtF,qHAAqH;AACtH,SAAA;AACD,QAAA,KAAK,EAAE;YACL,uFAAuF;YACvF,+CAA+C;AAChD,SAAA;;AAED,QAAA,WAAW,EAAE,CAAC,yCAAyC,EAAE,4BAA4B,CAAC;AACvF,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE;AACJ,gBAAA,IAAI,EAAE,uBAAuB;AAC7B,gBAAA,KAAK,EAAE,eAAe;AACvB,aAAA;AACF,SAAA;AACF,KAAA;AACF,CAAA,CAAC;AAEK,MAAM,gBAAgB,GAAc,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,KAAI;AAC9E,IAAA,MAAM,cAAc,GAAG,CAAC,CAAC,QAAQ;AAEjC,IAAA,MAAM,UAAU,GAAG,OAAO,CAAC,MAAK;QAC9B,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC;YACtD,SAAS;YACT,cAAc;AACf,SAAA,CAAC;AAEF,QAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;AACrE,IAAA,CAAC,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAE/B,IAAA,OAAO,cAAc,IACnBC,GAAA,CAAC,2BAA2B,EAAA,EAAA,GAAK,IAAI,EAAE,UAAU,EAAE,UAAU,EAAA,QAAA,EAC1D,QAAQ,EAAA,CACmB,KAE9BA,IAAC,sBAAsB,EAAA,EAAA,GAAK,IAAI,EAAE,UAAU,EAAE,UAAU,EAAA,CAAI,CAC7D;AACH;AAUA,MAAM,2BAA2B,GAAmB,CAAC,EACnD,kBAAkB,EAAE,eAAe,EACnC,UAAU,EACV,QAAQ,EACR,GAAG,IAAI,EACR,KAAI;AACH,IAAA,MAAM,aAAa,GAAG,KAAK,EAAE;AAE7B,IAAA,QACEA,GAAA,CAAC,sBAAsB,OACjB,IAAI,EACR,UAAU,EAAE,UAAU,EAAA,kBAAA,EACJ,CAAA,EAAG,aAAa,CAAA,EAAG,eAAe,GAAG,IAAI,eAAe,CAAA,CAAE,GAAG,EAAE,CAAA,CAAE,YAEnFA,GAAA,CAAA,KAAA,EAAA,EAAK,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,CAAC,WAAW,EAAA,QAAA,EACtD,QAAQ,EAAA,CACL,EAAA,CACiB;AAE7B,CAAC;AAED,MAAM,sBAAsB,GAAmB,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,MAC1FC,IAAA,CAAC,cAAc,EAAA,EAAC,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,IAAI,EAAA,QAAA,EAAA,CAChDD,GAAA,CAAC,WAAW,EAAA,EAAA,GAAK,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,KAAK,EAAA,QAAA,EAC/C,KAAK,GACM,EACb,QAAQ,CAAA,EAAA,CACM,CAClB;;"}
1
+ {"version":3,"file":"RadioButtonPanel.js","sources":["../../../src/components/RadioButtonPanel/RadioButtonPanel.tsx"],"sourcesContent":["import { type FC, type ReactNode, useId, useMemo } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { RadioButton } from '../RadioButton'\n\nimport { ClickablePanel } from './client'\n\nimport type { SHRComponentPropsWithRef } from '../../types'\n\ntype Props = SHRComponentPropsWithRef<\n typeof RadioButton,\n {\n label: ReactNode\n },\n { as: true }\n>\n\nconst classNameGenerator = tv({\n slots: {\n base: [\n 'smarthr-ui-RadioButtonPanel',\n 'shr-border-shorthand shr-cursor-pointer shr-list-none shr-shadow-none',\n 'has-[:disabled]:shr-cursor-default',\n // FIX: なぜか storybook 上で :has が動作しないので重ねて書いている\n 'has-[:focus-visible]:shr-focus-indicator [&:has(:focus-visible)]:shr-focus-indicator',\n '[&:has(:disabled)]:shr-text-disabled has-[:disabled]:[&_.smarthr-ui-RadioButtonPanel-description]:shr-text-disabled',\n ],\n radio: [\n '[&_.smarthr-ui-RadioButton-radioButton:focus-visible_+_span]:shr-focus-indicator-none',\n '[&_.smarthr-ui-RadioButton-label]:shr-ms-0.75',\n ],\n // RadioButtonPanel で指定している shr-ms-0.75 + RadioButton のボタンの shr-w-em を足して shr-ms-[1.75em] にしている\n description: ['smarthr-ui-RadioButtonPanel-description', 'shr-ms-[1.75em] shr-mt-0.5'],\n },\n variants: {\n hasDescription: {\n true: {\n base: 'shr-flex shr-flex-col',\n radio: 'shr-font-bold',\n },\n },\n },\n})\n\nexport const RadioButtonPanel: FC<Props> = ({ children, className, ...rest }) => {\n const hasDescription = !!children\n\n const classNames = useMemo(() => {\n const { base, description, radio } = classNameGenerator()\n\n return {\n base: base({ className, hasDescription }),\n description: description(),\n radio: radio({ hasDescription }),\n }\n }, [hasDescription, className])\n\n return hasDescription ? (\n <DescriptionRadioButtonPanel {...rest} classNames={classNames}>\n {children}\n </DescriptionRadioButtonPanel>\n ) : (\n <ActualRadioButtonPanel {...rest} classNames={classNames} />\n )\n}\n\ntype LowerProps = Omit<Props, 'className'> & {\n classNames: {\n base: string\n description: string\n radio: string\n }\n}\n\nconst DescriptionRadioButtonPanel: FC<LowerProps> = ({\n 'aria-describedby': ariaDescribedby,\n classNames,\n children,\n ...rest\n}) => {\n const descriptionId = useId()\n\n return (\n <ActualRadioButtonPanel\n {...rest}\n classNames={classNames}\n aria-describedby={`${descriptionId}${ariaDescribedby ? ` ${ariaDescribedby}` : ''}`}\n >\n <div id={descriptionId} className={classNames.description}>\n {children}\n </div>\n </ActualRadioButtonPanel>\n )\n}\n\nconst ActualRadioButtonPanel: FC<LowerProps> = ({ as, classNames, children, label, ...rest }) => (\n <ClickablePanel as={as} className={classNames.base}>\n <RadioButton {...rest} className={classNames.radio}>\n {label}\n </RadioButton>\n {children}\n </ClickablePanel>\n)\n"],"names":["tv","_jsx","_jsxs"],"mappings":";;;;;;AAiBA,MAAM,kBAAkB,GAAGA,EAAE,CAAC;AAC5B,IAAA,KAAK,EAAE;AACL,QAAA,IAAI,EAAE;YACJ,6BAA6B;YAC7B,uEAAuE;YACvE,oCAAoC;;YAEpC,sFAAsF;YACtF,qHAAqH;AACtH,SAAA;AACD,QAAA,KAAK,EAAE;YACL,uFAAuF;YACvF,+CAA+C;AAChD,SAAA;;AAED,QAAA,WAAW,EAAE,CAAC,yCAAyC,EAAE,4BAA4B,CAAC;AACvF,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE;AACJ,gBAAA,IAAI,EAAE,uBAAuB;AAC7B,gBAAA,KAAK,EAAE,eAAe;AACvB,aAAA;AACF,SAAA;AACF,KAAA;AACF,CAAA,CAAC;AAEK,MAAM,gBAAgB,GAAc,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,KAAI;AAC9E,IAAA,MAAM,cAAc,GAAG,CAAC,CAAC,QAAQ;AAEjC,IAAA,MAAM,UAAU,GAAG,OAAO,CAAC,MAAK;QAC9B,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,kBAAkB,EAAE;QAEzD,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;YACzC,WAAW,EAAE,WAAW,EAAE;AAC1B,YAAA,KAAK,EAAE,K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({
41
41
  },
42
42
  },
43
43
  });
44
- const SegmentedControl = ({ options, value, onClickOption, size = 'M', className, ...rest }) => {
44
+ const SegmentedControl = ({ options, value, defaultValue, onClickOption, size = 'M', className, ...rest }) => {
45
45
  const [isFocused, setIsFocused] = React.useState(false);
46
+ const [innerValue, setInnerValue] = React.useState(defaultValue ?? null);
47
+ const hasValue = value !== undefined;
48
+ const actualValue = hasValue ? value : innerValue;
46
49
  const classNames = React.useMemo(() => {
47
50
  const { container, buttonGroup, button } = classNameGenerator();
48
51
  return {
@@ -51,8 +54,7 @@ const SegmentedControl = ({ options, value, onClickOption, size = 'M', className
51
54
  button: button({ size }),
52
55
  };
53
56
  }, [size, className]);
54
- const latest = hooks_useLatest.useLatest({ onClickOption, isFocused });
55
- const hasOnClickOption = !!onClickOption;
57
+ const latest = hooks_useLatest.useLatest({ onClickOption, isFocused, hasValue });
56
58
  const functions = React.useMemo(() => ({
57
59
  callbackRef: (node) => {
58
60
  if (!node) {
@@ -101,19 +103,21 @@ const SegmentedControl = ({ options, value, onClickOption, size = 'M', className
101
103
  document.removeEventListener('keydown', handleKeyDown);
102
104
  };
103
105
  },
104
- handleClickOption: hasOnClickOption
105
- ? (e) => {
106
- latest.onClickOption?.(e.currentTarget.value);
106
+ handleClickOption: (e) => {
107
+ const clickedValue = e.currentTarget.value;
108
+ if (!latest.hasValue) {
109
+ setInnerValue(clickedValue);
107
110
  }
108
- : undefined,
111
+ latest.onClickOption?.(clickedValue);
112
+ },
109
113
  handleDelegateFocus: () => setIsFocused(true),
110
114
  handleDelegateBlur: () => setIsFocused(false),
111
- }), [hasOnClickOption, latest]);
112
- const excludesSelected = !value || options.every((option) => option.value !== value);
115
+ }), [latest]);
116
+ const excludesSelected = options.every((option) => option.value !== actualValue);
113
117
  return (jsxRuntime.jsx("div", { ...rest, ref: functions.callbackRef, role: "toolbar", className: classNames.container, onFocus: functions.handleDelegateFocus, onBlur: functions.handleDelegateBlur, children: jsxRuntime.jsx("div", { role: "radiogroup", className: classNames.buttonGroup, children: options.map((option, index) => {
114
- const checked = value === option.value;
118
+ const checked = actualValue === option.value;
115
119
  const { ariaLabel, ...optionRest } = option;
116
- return (React.createElement(SegmentedControlButton, { ...optionRest, key: option.value, checked: checked, tabIndex: !isFocused && (excludesSelected ? index === 0 : checked) ? 0 : -1, size: size, className: classNames.button, "aria-label": ariaLabel, "aria-checked": checked && !!value, handleClick: functions.handleClickOption }));
120
+ return (React.createElement(SegmentedControlButton, { ...optionRest, key: option.value, checked: checked, tabIndex: !isFocused && (excludesSelected ? index === 0 : checked) ? 0 : -1, size: size, className: classNames.button, "aria-label": ariaLabel, "aria-checked": checked, handleClick: functions.handleClickOption }));
117
121
  }) }) }));
118
122
  };
119
123
  const SegmentedControlButton = React.memo(({ checked, content, handleClick, ...rest }) => (
@@ -1 +1 @@
1
- {"version":3,"file":"SegmentedControl.cjs","sources":["../../../../src/components/SegmentedControl/client/SegmentedControl.tsx"],"sourcesContent":["'use client'\n\nimport { type FC, type MouseEvent, type ReactNode, memo, useMemo, useState } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { useLatest } from '../../../hooks/useLatest'\nimport { Button } from '../../Button'\n\nimport type { SHRComponentPropsWithoutRef } from '../../../types'\n\ntype Option = {\n /** 選択時に返される値 */\n value: string\n /** ボタンに表示する内容 */\n content: ReactNode\n /** ボタンの `aria-label` */\n ariaLabel?: string\n /** ボタンを disabled にするかどうか */\n disabled?: boolean\n}\n\ntype Props = SHRComponentPropsWithoutRef<\n 'div',\n {\n /** 選択肢の配列 */\n options: Option[]\n /** 選択中の値 */\n value?: string | null\n /** 選択肢を押下したときに発火するコールバック関数 */\n onClickOption?: (value: string) => void\n /** 各ボタンの大きさ */\n size?: 'M' | 'S'\n },\n { omit: 'role' | 'onFocus' | 'onBlur' }\n>\n\nconst classNameGenerator = tv({\n slots: {\n container: 'smarthr-ui-SegmentedControl shr-inline-flex',\n buttonGroup: 'shr-flex',\n button: [\n 'smarthr-ui-SegmentedControl-button',\n 'shr-m-0 shr--ml-px shr-rounded-none',\n 'focus-visible:shr-focus-indicator',\n 'first:shr-ml-0 first:shr-rounded-bl-m first:shr-rounded-tl-m',\n 'last:shr-rounded-br-m last:shr-rounded-tr-m',\n\n '[&:not([aria-checked=\"true\"]):focus-visible]:shr-relative [&:not([aria-checked=\"true\"]):focus-visible]:shr-border-x',\n\n // ::before: フォーカスリングと前のボタンの右端の間の隙間を埋めるために、左端から2px外側に1pxの縦線を描画する。\n // 非選択かつ先頭以外のボタンにフォーカスが当たったときのみ表示する\n 'before:-shr-left-[2px] before:shr-hidden before:shr-h-[calc(100%+2px)] before:shr-w-px before:shr-bg-border before:shr-content-[\"\"]',\n '[&:first-child]:before:shr-hidden [&:not([aria-checked=\"true\"]):not(:first-child):focus-visible]:before:shr-absolute [&:not([aria-checked=\"true\"]):not(:first-child):focus-visible]:before:shr-block',\n\n // ::after: フォーカスリングと次のボタンの左端の間の隙間を埋めるために、右端から2px外側に1pxの縦線を描画する。\n // 非選択かつ末尾以外のボタンにフォーカスが当たったときのみ表示する\n 'after:-shr-right-[2px] after:shr-hidden after:shr-h-[calc(100%+2px)] after:shr-w-px after:shr-bg-border after:shr-content-[\"\"]',\n '[&:last-child]:after:shr-hidden [&:not([aria-checked=\"true\"]):not(:last-child):focus-visible]:after:shr-absolute [&:not([aria-checked=\"true\"]):not(:last-child):focus-visible]:after:shr-block',\n ],\n },\n variants: {\n size: {\n M: {\n button: '[&:has(>_span_>_.smarthr-ui-Icon:only-child)]:shr-p-0.75',\n },\n S: {\n button: 'shr-p-0.5',\n },\n },\n },\n})\n\nexport const SegmentedControl: FC<Props> = ({\n options,\n value,\n onClickOption,\n size = 'M',\n className,\n ...rest\n}) => {\n const [isFocused, setIsFocused] = useState(false)\n\n const classNames = useMemo(() => {\n const { container, buttonGroup, button } = classNameGenerator()\n\n return {\n container: container({ className }),\n buttonGroup: buttonGroup(),\n button: button({ size }),\n }\n }, [size, className])\n\n const latest = useLatest({ onClickOption, isFocused })\n\n const hasOnClickOption = !!onClickOption\n\n const functions = useMemo(\n () => ({\n callbackRef: (node: HTMLElement | null) => {\n if (!node) {\n return\n }\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (!latest.isFocused || !document.activeElement) {\n return\n }\n\n let radios: NodeListOf<Element> | Element[] = node.querySelectorAll(\n '[role=\"radio\"]:not(:disabled)',\n )\n\n if (radios.length < 2) {\n return\n }\n\n radios = Array.from(radios)\n\n const focusedIndex = radios.indexOf(document.activeElement)\n\n if (focusedIndex === -1) {\n return\n }\n\n switch (e.key) {\n case 'Down':\n case 'ArrowDown':\n case 'Right':\n case 'ArrowRight': {\n const nextIndex = focusedIndex + 1\n const nextRadio = radios[nextIndex % radios.length]\n\n if (nextRadio instanceof HTMLButtonElement) {\n nextRadio.focus()\n }\n\n break\n }\n case 'Up':\n case 'ArrowUp':\n case 'Left':\n case 'ArrowLeft': {\n const nextIndex = focusedIndex - 1\n const nextRadio = radios[(nextIndex + radios.length) % radios.length]\n\n if (nextRadio instanceof HTMLButtonElement) {\n nextRadio.focus()\n }\n\n break\n }\n }\n }\n\n document.addEventListener('keydown', handleKeyDown)\n\n return () => {\n document.removeEventListener('keydown', handleKeyDown)\n }\n },\n handleClickOption: hasOnClickOption\n ? (e: MouseEvent<HTMLButtonElement>) => {\n latest.onClickOption?.(e.currentTarget.value)\n }\n : undefined,\n handleDelegateFocus: () => setIsFocused(true),\n handleDelegateBlur: () => setIsFocused(false),\n }),\n [hasOnClickOption, latest],\n )\n\n const excludesSelected = !value || options.every((option) => option.value !== value)\n\n return (\n <div\n {...rest}\n ref={functions.callbackRef}\n role=\"toolbar\"\n className={classNames.container}\n onFocus={functions.handleDelegateFocus}\n onBlur={functions.handleDelegateBlur}\n >\n <div role=\"radiogroup\" className={classNames.buttonGroup}>\n {options.map((option, index) => {\n const checked = value === option.value\n const { ariaLabel, ...optionRest } = option\n\n return (\n <SegmentedControlButton\n {...optionRest}\n key={option.value}\n checked={checked}\n tabIndex={!isFocused && (excludesSelected ? index === 0 : checked) ? 0 : -1}\n size={size}\n className={classNames.button}\n aria-label={ariaLabel}\n aria-checked={checked && !!value}\n handleClick={functions.handleClickOption}\n />\n )\n })}\n </div>\n </div>\n )\n}\n\nconst SegmentedControlButton = memo<\n Pick<Props, 'size'> &\n Omit<Props['options'][number], 'content' | 'ariaLabel'> & {\n content: ReactNode\n 'aria-label'?: string\n handleClick: undefined | ((e: MouseEvent<HTMLButtonElement>) => void)\n checked: boolean\n tabIndex: number\n 'aria-checked': boolean\n className: string\n }\n>(({ checked, content, handleClick, ...rest }) => (\n // eslint-disable-next-line smarthr/best-practice-for-interactive-element\n <Button {...rest} role=\"radio\" variant={checked ? 'primary' : 'secondary'} onClick={handleClick}>\n {content}\n </Button>\n))\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;AAoCA;AACE;AACE;AACA;AACA;;;;;;;;;;;;;;;AAkBC;AACF;AACD;AACE;AACE;AACE;AACD;AACD;AACE;AACD;AACF;AACF;AACF;;;AAYC;;;AAII;;AAEA;;AAEJ;;AAIA;AAEA;AAEI;;;;AAKE;;;;;AASE;;;AAIA;;AAIA;;;AAIA;AACE;AACA;AACA;;AAEE;;AAGA;;;;;AAMF;AACA;AACA;;AAEE;AACA;AAEA;;;;;;AAON;AAEA;AAEA;AACE;AACF;;AAEF;AACE;;;AAGA;AACF;AACA;AACD;;;AAiBK;;AAGA;AAaF;AAIR;AAEA;AAYE;AACAA;;"}
1
+ {"version":3,"file":"SegmentedControl.cjs","sources":["../../../../src/components/SegmentedControl/client/SegmentedControl.tsx"],"sourcesContent":["'use client'\n\nimport { type FC, type MouseEvent, type ReactNode, memo, useMemo, useState } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { useLatest } from '../../../hooks/useLatest'\nimport { Button } from '../../Button'\n\nimport type { SHRComponentPropsWithoutRef } from '../../../types'\n\ntype Option = {\n /** 選択時に返される値 */\n value: string\n /** ボタンに表示する内容 */\n content: ReactNode\n /** ボタンの `aria-label` */\n ariaLabel?: string\n /** ボタンを disabled にするかどうか */\n disabled?: boolean\n}\n\ntype Props = SHRComponentPropsWithoutRef<\n 'div',\n {\n /** 選択肢の配列 */\n options: Option[]\n /** 選択中の値 */\n value?: string | null\n /** デフォルトで選択する値 */\n defaultValue?: string | null\n /** 選択肢を押下したときに発火するコールバック関数 */\n onClickOption?: (value: string) => void\n /** 各ボタンの大きさ */\n size?: 'M' | 'S'\n },\n { omit: 'role' | 'onFocus' | 'onBlur' }\n>\n\nconst classNameGenerator = tv({\n slots: {\n container: 'smarthr-ui-SegmentedControl shr-inline-flex',\n buttonGroup: 'shr-flex',\n button: [\n 'smarthr-ui-SegmentedControl-button',\n 'shr-m-0 shr--ml-px shr-rounded-none',\n 'focus-visible:shr-focus-indicator',\n 'first:shr-ml-0 first:shr-rounded-bl-m first:shr-rounded-tl-m',\n 'last:shr-rounded-br-m last:shr-rounded-tr-m',\n\n '[&:not([aria-checked=\"true\"]):focus-visible]:shr-relative [&:not([aria-checked=\"true\"]):focus-visible]:shr-border-x',\n\n // ::before: フォーカスリングと前のボタンの右端の間の隙間を埋めるために、左端から2px外側に1pxの縦線を描画する。\n // 非選択かつ先頭以外のボタンにフォーカスが当たったときのみ表示する\n 'before:-shr-left-[2px] before:shr-hidden before:shr-h-[calc(100%+2px)] before:shr-w-px before:shr-bg-border before:shr-content-[\"\"]',\n '[&:first-child]:before:shr-hidden [&:not([aria-checked=\"true\"]):not(:first-child):focus-visible]:before:shr-absolute [&:not([aria-checked=\"true\"]):not(:first-child):focus-visible]:before:shr-block',\n\n // ::after: フォーカスリングと次のボタンの左端の間の隙間を埋めるために、右端から2px外側に1pxの縦線を描画する。\n // 非選択かつ末尾以外のボタンにフォーカスが当たったときのみ表示する\n 'after:-shr-right-[2px] after:shr-hidden after:shr-h-[calc(100%+2px)] after:shr-w-px after:shr-bg-border after:shr-content-[\"\"]',\n '[&:last-child]:after:shr-hidden [&:not([aria-checked=\"true\"]):not(:last-child):focus-visible]:after:shr-absolute [&:not([aria-checked=\"true\"]):not(:last-child):focus-visible]:after:shr-block',\n ],\n },\n variants: {\n size: {\n M: {\n button: '[&:has(>_span_>_.smarthr-ui-Icon:only-child)]:shr-p-0.75',\n },\n S: {\n button: 'shr-p-0.5',\n },\n },\n },\n})\n\nexport const SegmentedControl: FC<Props> = ({\n options,\n value,\n defaultValue,\n onClickOption,\n size = 'M',\n className,\n ...rest\n}) => {\n const [isFocused, setIsFocused] = useState(false)\n const [innerValue, setInnerValue] = useState(defaultValue ?? null)\n\n const hasValue = value !== undefined\n const actualValue = hasValue ? value : innerValue\n\n const classNames = useMemo(() => {\n const { container, buttonGroup, button } = classNameGenerator()\n\n return {\n container: container({ className }),\n buttonGroup: buttonGroup(),\n button: button({ size }),\n }\n }, [size, className])\n\n const latest = useLatest({ onClickOption, isFocused, hasValue })\n\n const functions = useMemo(\n () => ({\n callbackRef: (node: HTMLElement | null) => {\n if (!node) {\n return\n }\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (!latest.isFocused || !document.activeElement) {\n return\n }\n\n let radios: NodeListOf<Element> | Element[] = node.querySelectorAll(\n '[role=\"radio\"]:not(:disabled)',\n )\n\n if (radios.length < 2) {\n return\n }\n\n radios = Array.from(radios)\n\n const focusedIndex = radios.indexOf(document.activeElement)\n\n if (focusedIndex === -1) {\n return\n }\n\n switch (e.key) {\n case 'Down':\n case 'ArrowDown':\n case 'Right':\n case 'ArrowRight': {\n const nextIndex = focusedIndex + 1\n const nextRadio = radios[nextIndex % radios.length]\n\n if (nextRadio instanceof HTMLButtonElement) {\n nextRadio.focus()\n }\n\n break\n }\n case 'Up':\n case 'ArrowUp':\n case 'Left':\n case 'ArrowLeft': {\n const nextIndex = focusedIndex - 1\n const nextRadio = radios[(nextIndex + radios.length) % radios.length]\n\n if (nextRadio instanceof HTMLButtonElement) {\n nextRadio.focus()\n }\n\n break\n }\n }\n }\n\n document.addEventListener('keydown', handleKeyDown)\n\n return () => {\n document.removeEventListener('keydown', handleKeyDown)\n }\n },\n handleClickOption: (e: MouseEvent<HTMLButtonElement>) => {\n const clickedValue = e.currentTarget.value\n\n if (!latest.hasValue) {\n setInnerValue(clickedValue)\n }\n\n latest.onClickOption?.(clickedValue)\n },\n handleDelegateFocus: () => setIsFocused(true),\n handleDelegateBlur: () => setIsFocused(false),\n }),\n [latest],\n )\n\n const excludesSelected = options.every((option) => option.value !== actualValue)\n\n return (\n <div\n {...rest}\n ref={functions.callbackRef}\n role=\"toolbar\"\n className={classNames.container}\n onFocus={functions.handleDelegateFocus}\n onBlur={functions.handleDelegateBlur}\n >\n <div role=\"radiogroup\" className={classNames.buttonGroup}>\n {options.map((option, index) => {\n const checked = actualValue === option.value\n const { ariaLabel, ...optionRest } = option\n\n return (\n <SegmentedControlButton\n {...optionRest}\n key={option.value}\n checked={checked}\n tabIndex={!isFocused && (excludesSelected ? index === 0 : checked) ? 0 : -1}\n size={size}\n className={classNames.button}\n aria-label={ariaLabel}\n aria-checked={checked}\n handleClick={functions.handleClickOption}\n />\n )\n })}\n </div>\n </div>\n )\n}\n\nconst SegmentedControlButton = memo<\n Pick<Props, 'size'> &\n Omit<Props['options'][number], 'content' | 'ariaLabel'> & {\n content: ReactNode\n 'aria-label'?: string\n handleClick: (e: MouseEvent<HTMLButtonElement>) => void\n checked: boolean\n tabIndex: number\n 'aria-checked': boolean\n className: string\n }\n>(({ checked, content, handleClick, ...rest }) => (\n // eslint-disable-next-line smarthr/best-practice-for-interactive-element\n <Button {...rest} role=\"radio\" variant={checked ? 'primary' : 'secondary'} onClick={handleClick}>\n {content}\n </Button>\n))\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;AAsCA;AACE;AACE;AACA;AACA;;;;;;;;;;;;;;;AAkBC;AACF;AACD;AACE;AACE;AACE;AACD;AACD;AACE;AACD;AACF;AACF;AACF;AAEM;;AAUL;AAEA;;AAGA;;;AAII;;AAEA;;AAEJ;AAEA;AAEA;AAEI;;;;AAKE;;;;;AASE;;;AAIA;;AAIA;;;AAIA;AACE;AACA;AACA;;AAEE;;AAGA;;;;;AAMF;AACA;AACA;;AAEE;AACA;AAEA;;;;;;AAON;AAEA;AAEA;AACE;AACF;;AAEF;AACE;AAEA;;;AAIA;;AAEF;AACA;AACD;AAIH;;AAaQ;;AAGA;AAaF;AAIR;AAEA;AAYE;AACAA;;"}
@@ -15,6 +15,8 @@ type Props = SHRComponentPropsWithoutRef<'div', {
15
15
  options: Option[];
16
16
  /** 選択中の値 */
17
17
  value?: string | null;
18
+ /** デフォルトで選択する値 */
19
+ defaultValue?: string | null;
18
20
  /** 選択肢を押下したときに発火するコールバック関数 */
19
21
  onClickOption?: (value: string) => void;
20
22
  /** 各ボタンの大きさ */
@@ -39,8 +39,11 @@ const classNameGenerator = ce({
39
39
  },
40
40
  },
41
41
  });
42
- const SegmentedControl = ({ options, value, onClickOption, size = 'M', className, ...rest }) => {
42
+ const SegmentedControl = ({ options, value, defaultValue, onClickOption, size = 'M', className, ...rest }) => {
43
43
  const [isFocused, setIsFocused] = useState(false);
44
+ const [innerValue, setInnerValue] = useState(defaultValue ?? null);
45
+ const hasValue = value !== undefined;
46
+ const actualValue = hasValue ? value : innerValue;
44
47
  const classNames = useMemo(() => {
45
48
  const { container, buttonGroup, button } = classNameGenerator();
46
49
  return {
@@ -49,8 +52,7 @@ const SegmentedControl = ({ options, value, onClickOption, size = 'M', className
49
52
  button: button({ size }),
50
53
  };
51
54
  }, [size, className]);
52
- const latest = useLatest({ onClickOption, isFocused });
53
- const hasOnClickOption = !!onClickOption;
55
+ const latest = useLatest({ onClickOption, isFocused, hasValue });
54
56
  const functions = useMemo(() => ({
55
57
  callbackRef: (node) => {
56
58
  if (!node) {
@@ -99,19 +101,21 @@ const SegmentedControl = ({ options, value, onClickOption, size = 'M', className
99
101
  document.removeEventListener('keydown', handleKeyDown);
100
102
  };
101
103
  },
102
- handleClickOption: hasOnClickOption
103
- ? (e) => {
104
- latest.onClickOption?.(e.currentTarget.value);
104
+ handleClickOption: (e) => {
105
+ const clickedValue = e.currentTarget.value;
106
+ if (!latest.hasValue) {
107
+ setInnerValue(clickedValue);
105
108
  }
106
- : undefined,
109
+ latest.onClickOption?.(clickedValue);
110
+ },
107
111
  handleDelegateFocus: () => setIsFocused(true),
108
112
  handleDelegateBlur: () => setIsFocused(false),
109
- }), [hasOnClickOption, latest]);
110
- const excludesSelected = !value || options.every((option) => option.value !== value);
113
+ }), [latest]);
114
+ const excludesSelected = options.every((option) => option.value !== actualValue);
111
115
  return (jsx("div", { ...rest, ref: functions.callbackRef, role: "toolbar", className: classNames.container, onFocus: functions.handleDelegateFocus, onBlur: functions.handleDelegateBlur, children: jsx("div", { role: "radiogroup", className: classNames.buttonGroup, children: options.map((option, index) => {
112
- const checked = value === option.value;
116
+ const checked = actualValue === option.value;
113
117
  const { ariaLabel, ...optionRest } = option;
114
- return (createElement(SegmentedControlButton, { ...optionRest, key: option.value, checked: checked, tabIndex: !isFocused && (excludesSelected ? index === 0 : checked) ? 0 : -1, size: size, className: classNames.button, "aria-label": ariaLabel, "aria-checked": checked && !!value, handleClick: functions.handleClickOption }));
118
+ return (createElement(SegmentedControlButton, { ...optionRest, key: option.value, checked: checked, tabIndex: !isFocused && (excludesSelected ? index === 0 : checked) ? 0 : -1, size: size, className: classNames.button, "aria-label": ariaLabel, "aria-checked": checked, handleClick: functions.handleClickOption }));
115
119
  }) }) }));
116
120
  };
117
121
  const SegmentedControlButton = memo(({ checked, content, handleClick, ...rest }) => (
@@ -1 +1 @@
1
- {"version":3,"file":"SegmentedControl.js","sources":["../../../../src/components/SegmentedControl/client/SegmentedControl.tsx"],"sourcesContent":["'use client'\n\nimport { type FC, type MouseEvent, type ReactNode, memo, useMemo, useState } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { useLatest } from '../../../hooks/useLatest'\nimport { Button } from '../../Button'\n\nimport type { SHRComponentPropsWithoutRef } from '../../../types'\n\ntype Option = {\n /** 選択時に返される値 */\n value: string\n /** ボタンに表示する内容 */\n content: ReactNode\n /** ボタンの `aria-label` */\n ariaLabel?: string\n /** ボタンを disabled にするかどうか */\n disabled?: boolean\n}\n\ntype Props = SHRComponentPropsWithoutRef<\n 'div',\n {\n /** 選択肢の配列 */\n options: Option[]\n /** 選択中の値 */\n value?: string | null\n /** 選択肢を押下したときに発火するコールバック関数 */\n onClickOption?: (value: string) => void\n /** 各ボタンの大きさ */\n size?: 'M' | 'S'\n },\n { omit: 'role' | 'onFocus' | 'onBlur' }\n>\n\nconst classNameGenerator = tv({\n slots: {\n container: 'smarthr-ui-SegmentedControl shr-inline-flex',\n buttonGroup: 'shr-flex',\n button: [\n 'smarthr-ui-SegmentedControl-button',\n 'shr-m-0 shr--ml-px shr-rounded-none',\n 'focus-visible:shr-focus-indicator',\n 'first:shr-ml-0 first:shr-rounded-bl-m first:shr-rounded-tl-m',\n 'last:shr-rounded-br-m last:shr-rounded-tr-m',\n\n '[&:not([aria-checked=\"true\"]):focus-visible]:shr-relative [&:not([aria-checked=\"true\"]):focus-visible]:shr-border-x',\n\n // ::before: フォーカスリングと前のボタンの右端の間の隙間を埋めるために、左端から2px外側に1pxの縦線を描画する。\n // 非選択かつ先頭以外のボタンにフォーカスが当たったときのみ表示する\n 'before:-shr-left-[2px] before:shr-hidden before:shr-h-[calc(100%+2px)] before:shr-w-px before:shr-bg-border before:shr-content-[\"\"]',\n '[&:first-child]:before:shr-hidden [&:not([aria-checked=\"true\"]):not(:first-child):focus-visible]:before:shr-absolute [&:not([aria-checked=\"true\"]):not(:first-child):focus-visible]:before:shr-block',\n\n // ::after: フォーカスリングと次のボタンの左端の間の隙間を埋めるために、右端から2px外側に1pxの縦線を描画する。\n // 非選択かつ末尾以外のボタンにフォーカスが当たったときのみ表示する\n 'after:-shr-right-[2px] after:shr-hidden after:shr-h-[calc(100%+2px)] after:shr-w-px after:shr-bg-border after:shr-content-[\"\"]',\n '[&:last-child]:after:shr-hidden [&:not([aria-checked=\"true\"]):not(:last-child):focus-visible]:after:shr-absolute [&:not([aria-checked=\"true\"]):not(:last-child):focus-visible]:after:shr-block',\n ],\n },\n variants: {\n size: {\n M: {\n button: '[&:has(>_span_>_.smarthr-ui-Icon:only-child)]:shr-p-0.75',\n },\n S: {\n button: 'shr-p-0.5',\n },\n },\n },\n})\n\nexport const SegmentedControl: FC<Props> = ({\n options,\n value,\n onClickOption,\n size = 'M',\n className,\n ...rest\n}) => {\n const [isFocused, setIsFocused] = useState(false)\n\n const classNames = useMemo(() => {\n const { container, buttonGroup, button } = classNameGenerator()\n\n return {\n container: container({ className }),\n buttonGroup: buttonGroup(),\n button: button({ size }),\n }\n }, [size, className])\n\n const latest = useLatest({ onClickOption, isFocused })\n\n const hasOnClickOption = !!onClickOption\n\n const functions = useMemo(\n () => ({\n callbackRef: (node: HTMLElement | null) => {\n if (!node) {\n return\n }\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (!latest.isFocused || !document.activeElement) {\n return\n }\n\n let radios: NodeListOf<Element> | Element[] = node.querySelectorAll(\n '[role=\"radio\"]:not(:disabled)',\n )\n\n if (radios.length < 2) {\n return\n }\n\n radios = Array.from(radios)\n\n const focusedIndex = radios.indexOf(document.activeElement)\n\n if (focusedIndex === -1) {\n return\n }\n\n switch (e.key) {\n case 'Down':\n case 'ArrowDown':\n case 'Right':\n case 'ArrowRight': {\n const nextIndex = focusedIndex + 1\n const nextRadio = radios[nextIndex % radios.length]\n\n if (nextRadio instanceof HTMLButtonElement) {\n nextRadio.focus()\n }\n\n break\n }\n case 'Up':\n case 'ArrowUp':\n case 'Left':\n case 'ArrowLeft': {\n const nextIndex = focusedIndex - 1\n const nextRadio = radios[(nextIndex + radios.length) % radios.length]\n\n if (nextRadio instanceof HTMLButtonElement) {\n nextRadio.focus()\n }\n\n break\n }\n }\n }\n\n document.addEventListener('keydown', handleKeyDown)\n\n return () => {\n document.removeEventListener('keydown', handleKeyDown)\n }\n },\n handleClickOption: hasOnClickOption\n ? (e: MouseEvent<HTMLButtonElement>) => {\n latest.onClickOption?.(e.currentTarget.value)\n }\n : undefined,\n handleDelegateFocus: () => setIsFocused(true),\n handleDelegateBlur: () => setIsFocused(false),\n }),\n [hasOnClickOption, latest],\n )\n\n const excludesSelected = !value || options.every((option) => option.value !== value)\n\n return (\n <div\n {...rest}\n ref={functions.callbackRef}\n role=\"toolbar\"\n className={classNames.container}\n onFocus={functions.handleDelegateFocus}\n onBlur={functions.handleDelegateBlur}\n >\n <div role=\"radiogroup\" className={classNames.buttonGroup}>\n {options.map((option, index) => {\n const checked = value === option.value\n const { ariaLabel, ...optionRest } = option\n\n return (\n <SegmentedControlButton\n {...optionRest}\n key={option.value}\n checked={checked}\n tabIndex={!isFocused && (excludesSelected ? index === 0 : checked) ? 0 : -1}\n size={size}\n className={classNames.button}\n aria-label={ariaLabel}\n aria-checked={checked && !!value}\n handleClick={functions.handleClickOption}\n />\n )\n })}\n </div>\n </div>\n )\n}\n\nconst SegmentedControlButton = memo<\n Pick<Props, 'size'> &\n Omit<Props['options'][number], 'content' | 'ariaLabel'> & {\n content: ReactNode\n 'aria-label'?: string\n handleClick: undefined | ((e: MouseEvent<HTMLButtonElement>) => void)\n checked: boolean\n tabIndex: number\n 'aria-checked': boolean\n className: string\n }\n>(({ checked, content, handleClick, ...rest }) => (\n // eslint-disable-next-line smarthr/best-practice-for-interactive-element\n <Button {...rest} role=\"radio\" variant={checked ? 'primary' : 'secondary'} onClick={handleClick}>\n {content}\n </Button>\n))\n"],"names":["_jsx"],"mappings":";;;;;;;;;AAoCA;AACE;AACE;AACA;AACA;;;;;;;;;;;;;;;AAkBC;AACF;AACD;AACE;AACE;AACE;AACD;AACD;AACE;AACD;AACF;AACF;AACF;;;AAYC;;;AAII;;AAEA;;AAEJ;;AAIA;AAEA;AAEI;;;;AAKE;;;;;AASE;;;AAIA;;AAIA;;;AAIA;AACE;AACA;AACA;;AAEE;;AAGA;;;;;AAMF;AACA;AACA;;AAEE;AACA;AAEA;;;;;;AAON;AAEA;AAEA;AACE;AACF;;AAEF;AACE;;;AAGA;AACF;AACA;AACD;;;AAiBK;;AAGA;AAaF;AAIR;AAEA;AAYE;AACAA;;"}
1
+ {"version":3,"file":"SegmentedControl.js","sources":["../../../../src/components/SegmentedControl/client/SegmentedControl.tsx"],"sourcesContent":["'use client'\n\nimport { type FC, type MouseEvent, type ReactNode, memo, useMemo, useState } from 'react'\nimport { tv } from 'tailwind-variants'\n\nimport { useLatest } from '../../../hooks/useLatest'\nimport { Button } from '../../Button'\n\nimport type { SHRComponentPropsWithoutRef } from '../../../types'\n\ntype Option = {\n /** 選択時に返される値 */\n value: string\n /** ボタンに表示する内容 */\n content: ReactNode\n /** ボタンの `aria-label` */\n ariaLabel?: string\n /** ボタンを disabled にするかどうか */\n disabled?: boolean\n}\n\ntype Props = SHRComponentPropsWithoutRef<\n 'div',\n {\n /** 選択肢の配列 */\n options: Option[]\n /** 選択中の値 */\n value?: string | null\n /** デフォルトで選択する値 */\n defaultValue?: string | null\n /** 選択肢を押下したときに発火するコールバック関数 */\n onClickOption?: (value: string) => void\n /** 各ボタンの大きさ */\n size?: 'M' | 'S'\n },\n { omit: 'role' | 'onFocus' | 'onBlur' }\n>\n\nconst classNameGenerator = tv({\n slots: {\n container: 'smarthr-ui-SegmentedControl shr-inline-flex',\n buttonGroup: 'shr-flex',\n button: [\n 'smarthr-ui-SegmentedControl-button',\n 'shr-m-0 shr--ml-px shr-rounded-none',\n 'focus-visible:shr-focus-indicator',\n 'first:shr-ml-0 first:shr-rounded-bl-m first:shr-rounded-tl-m',\n 'last:shr-rounded-br-m last:shr-rounded-tr-m',\n\n '[&:not([aria-checked=\"true\"]):focus-visible]:shr-relative [&:not([aria-checked=\"true\"]):focus-visible]:shr-border-x',\n\n // ::before: フォーカスリングと前のボタンの右端の間の隙間を埋めるために、左端から2px外側に1pxの縦線を描画する。\n // 非選択かつ先頭以外のボタンにフォーカスが当たったときのみ表示する\n 'before:-shr-left-[2px] before:shr-hidden before:shr-h-[calc(100%+2px)] before:shr-w-px before:shr-bg-border before:shr-content-[\"\"]',\n '[&:first-child]:before:shr-hidden [&:not([aria-checked=\"true\"]):not(:first-child):focus-visible]:before:shr-absolute [&:not([aria-checked=\"true\"]):not(:first-child):focus-visible]:before:shr-block',\n\n // ::after: フォーカスリングと次のボタンの左端の間の隙間を埋めるために、右端から2px外側に1pxの縦線を描画する。\n // 非選択かつ末尾以外のボタンにフォーカスが当たったときのみ表示する\n 'after:-shr-right-[2px] after:shr-hidden after:shr-h-[calc(100%+2px)] after:shr-w-px after:shr-bg-border after:shr-content-[\"\"]',\n '[&:last-child]:after:shr-hidden [&:not([aria-checked=\"true\"]):not(:last-child):focus-visible]:after:shr-absolute [&:not([aria-checked=\"true\"]):not(:last-child):focus-visible]:after:shr-block',\n ],\n },\n variants: {\n size: {\n M: {\n button: '[&:has(>_span_>_.smarthr-ui-Icon:only-child)]:shr-p-0.75',\n },\n S: {\n button: 'shr-p-0.5',\n },\n },\n },\n})\n\nexport const SegmentedControl: FC<Props> = ({\n options,\n value,\n defaultValue,\n onClickOption,\n size = 'M',\n className,\n ...rest\n}) => {\n const [isFocused, setIsFocused] = useState(false)\n const [innerValue, setInnerValue] = useState(defaultValue ?? null)\n\n const hasValue = value !== undefined\n const actualValue = hasValue ? value : innerValue\n\n const classNames = useMemo(() => {\n const { container, buttonGroup, button } = classNameGenerator()\n\n return {\n container: container({ className }),\n buttonGroup: buttonGroup(),\n button: button({ size }),\n }\n }, [size, className])\n\n const latest = useLatest({ onClickOption, isFocused, hasValue })\n\n const functions = useMemo(\n () => ({\n callbackRef: (node: HTMLElement | null) => {\n if (!node) {\n return\n }\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (!latest.isFocused || !document.activeElement) {\n return\n }\n\n let radios: NodeListOf<Element> | Element[] = node.querySelectorAll(\n '[role=\"radio\"]:not(:disabled)',\n )\n\n if (radios.length < 2) {\n return\n }\n\n radios = Array.from(radios)\n\n const focusedIndex = radios.indexOf(document.activeElement)\n\n if (focusedIndex === -1) {\n return\n }\n\n switch (e.key) {\n case 'Down':\n case 'ArrowDown':\n case 'Right':\n case 'ArrowRight': {\n const nextIndex = focusedIndex + 1\n const nextRadio = radios[nextIndex % radios.length]\n\n if (nextRadio instanceof HTMLButtonElement) {\n nextRadio.focus()\n }\n\n break\n }\n case 'Up':\n case 'ArrowUp':\n case 'Left':\n case 'ArrowLeft': {\n const nextIndex = focusedIndex - 1\n const nextRadio = radios[(nextIndex + radios.length) % radios.length]\n\n if (nextRadio instanceof HTMLButtonElement) {\n nextRadio.focus()\n }\n\n break\n }\n }\n }\n\n document.addEventListener('keydown', handleKeyDown)\n\n return () => {\n document.removeEventListener('keydown', handleKeyDown)\n }\n },\n handleClickOption: (e: MouseEvent<HTMLButtonElement>) => {\n const clickedValue = e.currentTarget.value\n\n if (!latest.hasValue) {\n setInnerValue(clickedValue)\n }\n\n latest.onClickOption?.(clickedValue)\n },\n handleDelegateFocus: () => setIsFocused(true),\n handleDelegateBlur: () => setIsFocused(false),\n }),\n [latest],\n )\n\n const excludesSelected = options.every((option) => option.value !== actualValue)\n\n return (\n <div\n {...rest}\n ref={functions.callbackRef}\n role=\"toolbar\"\n className={classNames.container}\n onFocus={functions.handleDelegateFocus}\n onBlur={functions.handleDelegateBlur}\n >\n <div role=\"radiogroup\" className={classNames.buttonGroup}>\n {options.map((option, index) => {\n const checked = actualValue === option.value\n const { ariaLabel, ...optionRest } = option\n\n return (\n <SegmentedControlButton\n {...optionRest}\n key={option.value}\n checked={checked}\n tabIndex={!isFocused && (excludesSelected ? index === 0 : checked) ? 0 : -1}\n size={size}\n className={classNames.button}\n aria-label={ariaLabel}\n aria-checked={checked}\n handleClick={functions.handleClickOption}\n />\n )\n })}\n </div>\n </div>\n )\n}\n\nconst SegmentedControlButton = memo<\n Pick<Props, 'size'> &\n Omit<Props['options'][number], 'content' | 'ariaLabel'> & {\n content: ReactNode\n 'aria-label'?: string\n handleClick: (e: MouseEvent<HTMLButtonElement>) => void\n checked: boolean\n tabIndex: number\n 'aria-checked': boolean\n className: string\n }\n>(({ checked, content, handleClick, ...rest }) => (\n // eslint-disable-next-line smarthr/best-practice-for-interactive-element\n <Button {...rest} role=\"radio\" variant={checked ? 'primary' : 'secondary'} onClick={handleClick}>\n {content}\n </Button>\n))\n"],"names":["_jsx"],"mappings":";;;;;;;;;AAsCA;AACE;AACE;AACA;AACA;;;;;;;;;;;;;;;AAkBC;AACF;AACD;AACE;AACE;AACE;AACD;AACD;AACE;AACD;AACF;AACF;AACF;AAEM;;AAUL;AAEA;;AAGA;;;AAII;;AAEA;;AAEJ;AAEA;AAEA;AAEI;;;;AAKE;;;;;AASE;;;AAIA;;AAIA;;;AAIA;AACE;AACA;AACA;;AAEE;;AAGA;;;;;AAMF;AACA;AACA;;AAEE;AACA;AAEA;;;;;;AAON;AAEA;AAEA;AACE;AACF;;AAEF;AACE;AAEA;;;AAIA;;AAEF;AACA;AACD;AAIH;;AAaQ;;AAGA;AAaF;AAIR;AAEA;AAYE;AACAA;;"}