@charcoal-ui/react 5.2.0 → 5.3.0-beta.2

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.
@@ -13,6 +13,8 @@ export const StringSegments: StoryObj<typeof SegmentedControl> = {
13
13
  disabled: false,
14
14
  readonly: false,
15
15
  required: false,
16
+ uniformSegmentWidth: false,
17
+ fullWidth: false,
16
18
  },
17
19
  }
18
20
 
@@ -28,5 +30,91 @@ export const ObjectSegments: StoryObj<typeof SegmentedControl> = {
28
30
  disabled: false,
29
31
  readonly: false,
30
32
  required: false,
33
+ uniformSegmentWidth: false,
34
+ fullWidth: false,
35
+ },
36
+ }
37
+
38
+ export const RandomLengthSegments: StoryObj<typeof SegmentedControl> = {
39
+ args: {
40
+ name: 'test',
41
+ data: [
42
+ { label: 'なが〜〜い選択肢', value: 'option1' },
43
+ { label: '選', value: 'option2' },
44
+ { label: '選択肢', value: 'option3' },
45
+ ],
46
+ disabled: false,
47
+ readonly: false,
48
+ required: false,
49
+ uniformSegmentWidth: false,
50
+ fullWidth: false,
51
+ },
52
+ }
53
+
54
+ export const UniformWidthSegments: StoryObj<typeof SegmentedControl> = {
55
+ args: {
56
+ name: 'test',
57
+ data: [
58
+ { label: 'なが〜〜い選択肢', value: 'option1' },
59
+ { label: '選', value: 'option2' },
60
+ { label: '選択肢', value: 'option3' },
61
+ ],
62
+ disabled: false,
63
+ readonly: false,
64
+ required: false,
65
+ uniformSegmentWidth: true,
66
+ fullWidth: false,
67
+ },
68
+ }
69
+
70
+ export const UniformWidthSegmentsWhenShortLabel: StoryObj<
71
+ typeof SegmentedControl
72
+ > = {
73
+ args: {
74
+ name: 'test',
75
+ data: [
76
+ { label: '選', value: 'option1' },
77
+ { label: '択', value: 'option2' },
78
+ { label: '肢', value: 'option3' },
79
+ ],
80
+ disabled: false,
81
+ readonly: false,
82
+ required: false,
83
+ uniformSegmentWidth: true,
84
+ fullWidth: false,
85
+ },
86
+ }
87
+
88
+ export const FullWidthSegments: StoryObj<typeof SegmentedControl> = {
89
+ args: {
90
+ name: 'test',
91
+ data: [
92
+ { label: '選択肢1', value: 'option1' },
93
+ { label: '選択肢2', value: 'option2' },
94
+ { label: '選択肢3', value: 'option3' },
95
+ ],
96
+ disabled: false,
97
+ readonly: false,
98
+ required: false,
99
+ uniformSegmentWidth: false,
100
+ fullWidth: true,
101
+ },
102
+ }
103
+
104
+ export const UniformWidthAndFullWidthSegments: StoryObj<
105
+ typeof SegmentedControl
106
+ > = {
107
+ args: {
108
+ name: 'test',
109
+ data: [
110
+ { label: 'なが〜〜い選択肢', value: 'option1' },
111
+ { label: '選', value: 'option2' },
112
+ { label: '選択肢', value: 'option3' },
113
+ ],
114
+ disabled: false,
115
+ readonly: false,
116
+ required: false,
117
+ uniformSegmentWidth: true,
118
+ fullWidth: true,
31
119
  },
32
120
  }
@@ -25,6 +25,8 @@ export type SegmentedControlProps = {
25
25
  readonly readonly?: boolean
26
26
  readonly required?: boolean
27
27
  readonly className?: string
28
+ readonly uniformSegmentWidth?: boolean
29
+ readonly fullWidth?: boolean
28
30
 
29
31
  readonly value?: string
30
32
  readonly defaultValue?: string
@@ -60,13 +62,20 @@ const SegmentedControl = forwardRef<HTMLDivElement, SegmentedControlProps>(
60
62
  }, [props.data])
61
63
 
62
64
  return (
63
- <div ref={ref} {...radioGroupProps} className={className}>
65
+ <div
66
+ ref={ref}
67
+ {...radioGroupProps}
68
+ className={className}
69
+ data-uniform-segment-width={props.uniformSegmentWidth}
70
+ data-full-width={props.fullWidth}
71
+ >
64
72
  <RadioProvider value={state}>
65
73
  {segmentedControlItems.map((item) => (
66
74
  <Segmented
67
75
  key={item.value}
68
76
  value={item.value}
69
77
  disabled={item.disabled}
78
+ uniformSegmentWidth={props.uniformSegmentWidth}
70
79
  >
71
80
  {item.label}
72
81
  </Segmented>
@@ -83,6 +92,8 @@ type RadioProps = {
83
92
  value: string
84
93
  disabled?: boolean
85
94
  children?: ReactNode
95
+ uniformSegmentWidth?: boolean
96
+ fullWidth?: boolean
86
97
  }
87
98
 
88
99
  const Segmented = (props: RadioProps) => {
@@ -108,6 +119,8 @@ const Segmented = (props: RadioProps) => {
108
119
  className="charcoal-segmented-control-radio__label"
109
120
  aria-disabled={isDisabled || state.isReadOnly}
110
121
  data-checked={isSelected}
122
+ data-uniform-segment-width={props.uniformSegmentWidth}
123
+ data-full-width={props.fullWidth}
111
124
  >
112
125
  <input
113
126
  className="charcoal-segmented-control-radio__input"