@ckwag/elements 0.0.1
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.
- package/LICENSE +191 -0
- package/README.md +63 -0
- package/dist/Button/Button.css +235 -0
- package/dist/Button/Button.d.ts +35 -0
- package/dist/Button/Button.d.ts.map +1 -0
- package/dist/Button/Button.js +27 -0
- package/dist/Button/Button.js.map +1 -0
- package/dist/Button/index.d.ts +3 -0
- package/dist/Button/index.d.ts.map +1 -0
- package/dist/Button/index.js +2 -0
- package/dist/Button/index.js.map +1 -0
- package/dist/InlineMessage/InlineMessage.css +161 -0
- package/dist/InlineMessage/InlineMessage.d.ts +30 -0
- package/dist/InlineMessage/InlineMessage.d.ts.map +1 -0
- package/dist/InlineMessage/InlineMessage.js +39 -0
- package/dist/InlineMessage/InlineMessage.js.map +1 -0
- package/dist/InlineMessage/index.d.ts +3 -0
- package/dist/InlineMessage/index.d.ts.map +1 -0
- package/dist/InlineMessage/index.js +2 -0
- package/dist/InlineMessage/index.js.map +1 -0
- package/dist/InputField/InputField.css +275 -0
- package/dist/InputField/InputField.d.ts +43 -0
- package/dist/InputField/InputField.d.ts.map +1 -0
- package/dist/InputField/InputField.js +39 -0
- package/dist/InputField/InputField.js.map +1 -0
- package/dist/InputField/index.d.ts +3 -0
- package/dist/InputField/index.d.ts.map +1 -0
- package/dist/InputField/index.js +2 -0
- package/dist/InputField/index.js.map +1 -0
- package/dist/SegmentedControl/SegmentedControl.css +235 -0
- package/dist/SegmentedControl/SegmentedControl.d.ts +46 -0
- package/dist/SegmentedControl/SegmentedControl.d.ts.map +1 -0
- package/dist/SegmentedControl/SegmentedControl.js +117 -0
- package/dist/SegmentedControl/SegmentedControl.js.map +1 -0
- package/dist/SegmentedControl/index.d.ts +3 -0
- package/dist/SegmentedControl/index.d.ts.map +1 -0
- package/dist/SegmentedControl/index.js +2 -0
- package/dist/SegmentedControl/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +9 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +6 -0
- package/dist/react/index.js.map +1 -0
- package/dist/styles.css +4 -0
- package/package.json +64 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Segmented Control Styles
|
|
3
|
+
*
|
|
4
|
+
* Uses only semantic design tokens from @ckwag/elements-tokens.
|
|
5
|
+
* Container is a pill-shaped track with a sliding indicator behind segments.
|
|
6
|
+
*
|
|
7
|
+
* Types: Default (auto-width), Fill (equal-width stretch)
|
|
8
|
+
* Content modes: label, icon-label, icon-compact
|
|
9
|
+
* States: Default, Hover, Active (sliding indicator)
|
|
10
|
+
*
|
|
11
|
+
* Icon-compact uses CSS grid `0fr → 1fr` on each segment to animate the label
|
|
12
|
+
* width. The indicator is positioned via offsetLeft/offsetWidth in a
|
|
13
|
+
* useLayoutEffect — no hidden measurer needed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/* ============================================
|
|
17
|
+
Container
|
|
18
|
+
============================================ */
|
|
19
|
+
|
|
20
|
+
.ckw-segmented-control {
|
|
21
|
+
position: relative;
|
|
22
|
+
display: inline-flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
gap: var(--spacing-3xs);
|
|
25
|
+
padding: var(--spacing-2xs);
|
|
26
|
+
background-color: var(--background-control);
|
|
27
|
+
border: var(--border-weight-s) solid var(--border-soft);
|
|
28
|
+
border-radius: var(--border-radius-full);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.ckw-segmented-control--fill {
|
|
32
|
+
display: flex;
|
|
33
|
+
width: 100%;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* ============================================
|
|
37
|
+
Sliding Indicator
|
|
38
|
+
============================================ */
|
|
39
|
+
|
|
40
|
+
.ckw-segmented-control__indicator {
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: var(--spacing-2xs);
|
|
43
|
+
bottom: var(--spacing-2xs);
|
|
44
|
+
left: 0;
|
|
45
|
+
box-sizing: border-box;
|
|
46
|
+
background-color: var(--background-active);
|
|
47
|
+
border: var(--border-weight-s) solid var(--border-active);
|
|
48
|
+
border-radius: var(--border-radius-full);
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
will-change: transform, width;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.ckw-segmented-control__indicator--animated {
|
|
54
|
+
transition:
|
|
55
|
+
transform 250ms cubic-bezier(0.4, 0, 0.2, 1),
|
|
56
|
+
width 250ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* ============================================
|
|
60
|
+
Segment (button)
|
|
61
|
+
============================================ */
|
|
62
|
+
|
|
63
|
+
.ckw-segmented-control__segment {
|
|
64
|
+
position: relative;
|
|
65
|
+
z-index: 1;
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
gap: var(--spacing-2xs);
|
|
70
|
+
height: var(--spacing-2xl);
|
|
71
|
+
padding: var(--spacing-2xs) var(--spacing-m);
|
|
72
|
+
border: var(--border-weight-s) solid transparent;
|
|
73
|
+
border-radius: var(--border-radius-full);
|
|
74
|
+
background: none;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
white-space: nowrap;
|
|
77
|
+
transition: background-color 150ms ease;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.ckw-segmented-control--fill .ckw-segmented-control__segment {
|
|
81
|
+
flex: 1 0 0;
|
|
82
|
+
min-width: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Icon-compact segment: flexbox with centered content.
|
|
87
|
+
* The inner wrapper handles the grid animation for label collapse.
|
|
88
|
+
*/
|
|
89
|
+
.ckw-segmented-control__segment--compact {
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
justify-content: center;
|
|
93
|
+
gap: 0;
|
|
94
|
+
padding: var(--spacing-2xs) var(--spacing-m);
|
|
95
|
+
transition: background-color 150ms ease;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* Inner wrapper for icon-compact: CSS grid animates label column.
|
|
100
|
+
* Columns: [icon: auto] [label: 0fr or 1fr]
|
|
101
|
+
*/
|
|
102
|
+
.ckw-segmented-control__compact-inner {
|
|
103
|
+
display: grid;
|
|
104
|
+
grid-template-columns: auto 0fr;
|
|
105
|
+
align-items: center;
|
|
106
|
+
width: max-content;
|
|
107
|
+
transition: grid-template-columns 250ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.ckw-segmented-control__segment--active .ckw-segmented-control__compact-inner {
|
|
111
|
+
grid-template-columns: auto 1fr;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Fill + compact: all segments equal width (1/n) by default.
|
|
115
|
+
When the active label needs more space, min-width: max-content
|
|
116
|
+
pushes it wider and the inactives shrink to accommodate. */
|
|
117
|
+
.ckw-segmented-control--fill .ckw-segmented-control__segment--compact {
|
|
118
|
+
flex: 1 1 0;
|
|
119
|
+
min-width: 0;
|
|
120
|
+
overflow: hidden;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.ckw-segmented-control--fill
|
|
124
|
+
.ckw-segmented-control__segment--compact.ckw-segmented-control__segment--active {
|
|
125
|
+
min-width: max-content;
|
|
126
|
+
overflow: visible;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* Hover (non-active only) */
|
|
130
|
+
.ckw-segmented-control__segment:hover:not(.ckw-segmented-control__segment--active) {
|
|
131
|
+
background-color: var(--background-hover);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* Active — visuals come from the indicator behind, keep segment transparent */
|
|
135
|
+
.ckw-segmented-control__segment--active {
|
|
136
|
+
background: none;
|
|
137
|
+
border-color: transparent;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* Focus */
|
|
141
|
+
.ckw-segmented-control__segment:focus-visible {
|
|
142
|
+
outline: var(--border-weight-m) solid var(--border-active);
|
|
143
|
+
outline-offset: 2px;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* ============================================
|
|
147
|
+
Label
|
|
148
|
+
============================================ */
|
|
149
|
+
|
|
150
|
+
.ckw-segmented-control__label {
|
|
151
|
+
font-family: var(--font-family-brand), sans-serif;
|
|
152
|
+
font-size: var(--label-m-size);
|
|
153
|
+
line-height: var(--label-m-height);
|
|
154
|
+
font-weight: var(--label-m-weight);
|
|
155
|
+
color: var(--text-secondary);
|
|
156
|
+
overflow: hidden;
|
|
157
|
+
text-overflow: ellipsis;
|
|
158
|
+
transition: color 150ms ease;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.ckw-segmented-control__segment--active .ckw-segmented-control__label {
|
|
162
|
+
color: var(--text-on-interactive-secondary);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/*
|
|
166
|
+
* Icon-compact label: lives in the second grid column.
|
|
167
|
+
* When inactive the column is 0fr so the label collapses.
|
|
168
|
+
* Opacity fades slightly faster than the width collapse so
|
|
169
|
+
* truncated text is never visible.
|
|
170
|
+
*/
|
|
171
|
+
.ckw-segmented-control__label--compact {
|
|
172
|
+
display: block;
|
|
173
|
+
overflow: hidden;
|
|
174
|
+
white-space: nowrap;
|
|
175
|
+
text-overflow: clip;
|
|
176
|
+
min-width: 0;
|
|
177
|
+
margin-left: var(--spacing-2xs);
|
|
178
|
+
opacity: 1;
|
|
179
|
+
transition:
|
|
180
|
+
opacity 150ms cubic-bezier(0.4, 0, 0.2, 1) 100ms,
|
|
181
|
+
margin-left 250ms cubic-bezier(0.4, 0, 0.2, 1),
|
|
182
|
+
color 150ms ease;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.ckw-segmented-control__label--faded {
|
|
186
|
+
margin-left: 0;
|
|
187
|
+
opacity: 0;
|
|
188
|
+
transition:
|
|
189
|
+
opacity 80ms cubic-bezier(0.4, 0, 0.2, 1),
|
|
190
|
+
margin-left 250ms cubic-bezier(0.4, 0, 0.2, 1),
|
|
191
|
+
color 150ms ease;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* ============================================
|
|
195
|
+
Icon
|
|
196
|
+
============================================ */
|
|
197
|
+
|
|
198
|
+
.ckw-segmented-control__icon {
|
|
199
|
+
display: flex;
|
|
200
|
+
align-items: center;
|
|
201
|
+
justify-content: center;
|
|
202
|
+
width: 24px;
|
|
203
|
+
height: 24px;
|
|
204
|
+
flex-shrink: 0;
|
|
205
|
+
color: var(--text-secondary);
|
|
206
|
+
transition: color 150ms ease;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.ckw-segmented-control__icon > svg {
|
|
210
|
+
width: 100%;
|
|
211
|
+
height: 100%;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.ckw-segmented-control__segment--active .ckw-segmented-control__icon {
|
|
215
|
+
color: var(--text-on-interactive-secondary);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/* ============================================
|
|
219
|
+
Docs-only forced states
|
|
220
|
+
============================================ */
|
|
221
|
+
|
|
222
|
+
.ckw-segmented-control--state-hover
|
|
223
|
+
.ckw-segmented-control__segment:first-child:not(.ckw-segmented-control__segment--active) {
|
|
224
|
+
background-color: var(--background-hover);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.ckw-segmented-control--state-focus-visible .ckw-segmented-control__segment:first-child {
|
|
228
|
+
outline: var(--border-weight-m) solid var(--border-active);
|
|
229
|
+
outline-offset: 2px;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.ckw-segmented-control--state-disabled {
|
|
233
|
+
opacity: 0.4;
|
|
234
|
+
pointer-events: none;
|
|
235
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './SegmentedControl.css';
|
|
3
|
+
export type SegmentedControlType = 'Default' | 'Fill';
|
|
4
|
+
export type SegmentedControlContentMode = 'label' | 'icon-label' | 'icon-compact';
|
|
5
|
+
export interface Segment {
|
|
6
|
+
/** Unique value identifying this segment. */
|
|
7
|
+
value: string;
|
|
8
|
+
/** Visible label text. */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** Optional icon (24×24 SVG recommended). */
|
|
11
|
+
icon?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export interface SegmentedControlProps {
|
|
14
|
+
/** Array of segments to render. Minimum 2. */
|
|
15
|
+
segments: Segment[];
|
|
16
|
+
/** The `value` of the currently active segment. */
|
|
17
|
+
activeValue: string;
|
|
18
|
+
/** Called when the user selects a different segment. */
|
|
19
|
+
onChange?: (value: string) => void;
|
|
20
|
+
/** Layout type. Default = auto-width segments; Fill = equal-width stretch. */
|
|
21
|
+
type?: SegmentedControlType;
|
|
22
|
+
/**
|
|
23
|
+
* Content display mode:
|
|
24
|
+
* - `label` — label only (default)
|
|
25
|
+
* - `icon-label` — icon + label on all segments
|
|
26
|
+
* - `icon-compact` — active shows icon + label, inactive show icon only;
|
|
27
|
+
* uses CSS grid `0fr → 1fr` for smooth label animation.
|
|
28
|
+
*/
|
|
29
|
+
contentMode?: SegmentedControlContentMode;
|
|
30
|
+
/** Additional CSS class names on the outer container. */
|
|
31
|
+
className?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Segmented Control allows users to switch between related options,
|
|
35
|
+
* views, or states within the same context.
|
|
36
|
+
*
|
|
37
|
+
* Features a sliding indicator that smoothly animates between segments.
|
|
38
|
+
* Supports three content modes: label-only, icon + label, and icon-compact.
|
|
39
|
+
* In icon-compact mode, each segment uses CSS grid with `0fr → 1fr` column
|
|
40
|
+
* transitions to animate the label width — no hidden measurer needed.
|
|
41
|
+
* The indicator is positioned via offsetLeft/offsetWidth in a useLayoutEffect.
|
|
42
|
+
* Two layout types: Default (auto-width) and Fill (equal-width stretch).
|
|
43
|
+
* All styling uses semantic design tokens.
|
|
44
|
+
*/
|
|
45
|
+
export declare function SegmentedControl({ segments, activeValue, onChange, type, contentMode, className, }: SegmentedControlProps): React.JSX.Element;
|
|
46
|
+
//# sourceMappingURL=SegmentedControl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,wBAAwB,CAAC;AAEhC,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,MAAM,CAAC;AACtD,MAAM,MAAM,2BAA2B,GAAG,OAAO,GAAG,YAAY,GAAG,cAAc,CAAC;AAKlF,MAAM,WAAW,OAAO;IACtB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,8CAA8C;IAC9C,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,8EAA8E;IAC9E,IAAI,CAAC,EAAE,oBAAoB,CAAC;IAC5B;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,2BAA2B,CAAC;IAC1C,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,IAAgB,EAChB,WAAqB,EACrB,SAAS,GACV,EAAE,qBAAqB,qBAuJvB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './SegmentedControl.css';
|
|
3
|
+
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;
|
|
4
|
+
// ---
|
|
5
|
+
/**
|
|
6
|
+
* Segmented Control allows users to switch between related options,
|
|
7
|
+
* views, or states within the same context.
|
|
8
|
+
*
|
|
9
|
+
* Features a sliding indicator that smoothly animates between segments.
|
|
10
|
+
* Supports three content modes: label-only, icon + label, and icon-compact.
|
|
11
|
+
* In icon-compact mode, each segment uses CSS grid with `0fr → 1fr` column
|
|
12
|
+
* transitions to animate the label width — no hidden measurer needed.
|
|
13
|
+
* The indicator is positioned via offsetLeft/offsetWidth in a useLayoutEffect.
|
|
14
|
+
* Two layout types: Default (auto-width) and Fill (equal-width stretch).
|
|
15
|
+
* All styling uses semantic design tokens.
|
|
16
|
+
*/
|
|
17
|
+
export function SegmentedControl({ segments, activeValue, onChange, type = 'Default', contentMode = 'label', className, }) {
|
|
18
|
+
const containerRef = React.useRef(null);
|
|
19
|
+
const segmentRefs = React.useRef(new Map());
|
|
20
|
+
const [indicator, setIndicator] = React.useState(null);
|
|
21
|
+
const [hasAnimated, setHasAnimated] = React.useState(false);
|
|
22
|
+
const isCompact = contentMode === 'icon-compact';
|
|
23
|
+
// Stable key so effects don't re-fire on new array references.
|
|
24
|
+
const segmentsKey = segments.map((s) => `${s.value}:${s.label ?? ''}`).join('|');
|
|
25
|
+
// --- Indicator positioning (all modes) ---
|
|
26
|
+
const updateIndicator = React.useCallback(() => {
|
|
27
|
+
const container = containerRef.current;
|
|
28
|
+
const activeEl = segmentRefs.current.get(activeValue);
|
|
29
|
+
if (!container || !activeEl) {
|
|
30
|
+
setIndicator(null);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const cRect = container.getBoundingClientRect();
|
|
34
|
+
const aRect = activeEl.getBoundingClientRect();
|
|
35
|
+
const borderLeft = parseFloat(getComputedStyle(container).borderLeftWidth) || 0;
|
|
36
|
+
setIndicator({ left: aRect.left - cRect.left - borderLeft, width: aRect.width });
|
|
37
|
+
}, [activeValue]);
|
|
38
|
+
// Position on mount + when active changes
|
|
39
|
+
useIsomorphicLayoutEffect(() => {
|
|
40
|
+
updateIndicator();
|
|
41
|
+
if (!hasAnimated) {
|
|
42
|
+
requestAnimationFrame(() => setHasAnimated(true));
|
|
43
|
+
}
|
|
44
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
|
+
}, [activeValue, segmentsKey, type, contentMode, hasAnimated]);
|
|
46
|
+
// For compact mode: the grid transition changes segment widths over 250ms.
|
|
47
|
+
// We need to keep re-measuring the indicator during the transition so it
|
|
48
|
+
// tracks the active segment's position as it expands/collapses.
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
if (!isCompact || !hasAnimated)
|
|
51
|
+
return;
|
|
52
|
+
let frameId;
|
|
53
|
+
const start = performance.now();
|
|
54
|
+
const duration = 280; // slightly longer than 250ms transition to be safe
|
|
55
|
+
const tick = () => {
|
|
56
|
+
updateIndicator();
|
|
57
|
+
if (performance.now() - start < duration) {
|
|
58
|
+
frameId = requestAnimationFrame(tick);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
frameId = requestAnimationFrame(tick);
|
|
62
|
+
return () => cancelAnimationFrame(frameId);
|
|
63
|
+
}, [isCompact, hasAnimated, activeValue, updateIndicator]);
|
|
64
|
+
// --- Render ---
|
|
65
|
+
const classes = [
|
|
66
|
+
'ckw-segmented-control',
|
|
67
|
+
isCompact ? 'ckw-segmented-control--compact' : '',
|
|
68
|
+
type === 'Fill' ? 'ckw-segmented-control--fill' : '',
|
|
69
|
+
className ?? '',
|
|
70
|
+
]
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join(' ');
|
|
73
|
+
return (React.createElement("div", { className: classes, role: "tablist", ref: containerRef },
|
|
74
|
+
indicator && (React.createElement("div", { className: [
|
|
75
|
+
'ckw-segmented-control__indicator',
|
|
76
|
+
hasAnimated ? 'ckw-segmented-control__indicator--animated' : '',
|
|
77
|
+
]
|
|
78
|
+
.filter(Boolean)
|
|
79
|
+
.join(' '), style: {
|
|
80
|
+
transform: `translateX(${indicator.left}px)`,
|
|
81
|
+
width: `${indicator.width}px`,
|
|
82
|
+
} })),
|
|
83
|
+
segments.map((segment) => {
|
|
84
|
+
const isActive = segment.value === activeValue;
|
|
85
|
+
const showIcon = contentMode === 'icon-label' || isCompact;
|
|
86
|
+
const showLabel = contentMode === 'label' || contentMode === 'icon-label' || isCompact;
|
|
87
|
+
const segmentClasses = [
|
|
88
|
+
'ckw-segmented-control__segment',
|
|
89
|
+
isActive ? 'ckw-segmented-control__segment--active' : '',
|
|
90
|
+
isCompact ? 'ckw-segmented-control__segment--compact' : '',
|
|
91
|
+
]
|
|
92
|
+
.filter(Boolean)
|
|
93
|
+
.join(' ');
|
|
94
|
+
const labelClasses = [
|
|
95
|
+
'ckw-segmented-control__label',
|
|
96
|
+
isCompact ? 'ckw-segmented-control__label--compact' : '',
|
|
97
|
+
isCompact && !isActive ? 'ckw-segmented-control__label--faded' : '',
|
|
98
|
+
]
|
|
99
|
+
.filter(Boolean)
|
|
100
|
+
.join(' ');
|
|
101
|
+
return (React.createElement("button", { key: segment.value, ref: (el) => {
|
|
102
|
+
if (el) {
|
|
103
|
+
segmentRefs.current.set(segment.value, el);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
segmentRefs.current.delete(segment.value);
|
|
107
|
+
}
|
|
108
|
+
}, className: segmentClasses, role: "tab", "aria-selected": isActive, "aria-label": segment.label, tabIndex: isActive ? 0 : -1, onClick: () => onChange?.(segment.value) }, isCompact ? (
|
|
109
|
+
/* Compact: inner wrapper so icon+label stay grouped for centering */
|
|
110
|
+
React.createElement("span", { className: "ckw-segmented-control__compact-inner" },
|
|
111
|
+
segment.icon && (React.createElement("span", { className: "ckw-segmented-control__icon" }, segment.icon)),
|
|
112
|
+
segment.label && React.createElement("span", { className: labelClasses }, segment.label))) : (React.createElement(React.Fragment, null,
|
|
113
|
+
showIcon && segment.icon && (React.createElement("span", { className: "ckw-segmented-control__icon" }, segment.icon)),
|
|
114
|
+
showLabel && segment.label && (React.createElement("span", { className: labelClasses }, segment.label))))));
|
|
115
|
+
})));
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=SegmentedControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SegmentedControl.js","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,wBAAwB,CAAC;AAKhC,MAAM,yBAAyB,GAC7B,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC;AAgC1E,MAAM;AAEN;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,IAAI,GAAG,SAAS,EAChB,WAAW,GAAG,OAAO,EACrB,SAAS,GACa;IACtB,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAiB,IAAI,CAAC,CAAC;IACxD,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAiC,IAAI,GAAG,EAAE,CAAC,CAAC;IAE5E,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAGtC,IAAI,CAAC,CAAC;IAChB,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,MAAM,SAAS,GAAG,WAAW,KAAK,cAAc,CAAC;IAEjD,+DAA+D;IAC/D,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,EAAE,CA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AC,CAAC,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAEvC,SAAS,CAAC,CAAC,CAAC;YACX,qEAAqE;YACrE,8BAAM,SAAS,EAAC,sCAAsC;gBACnD,OAAO,CAAC,IAAI,IAAI,CACf,8BAAM,SAAS,EAAC,6BAA6B,IAAE,OAAO,CAAC,IAAI,CAAQ,CACpE;gBACA,OAAO,CAAC,KAAK,IAAI,8BAAM,SAAS,EAAE,YAAY,IAAG,OAAO,CAAC,KAAK,CAAQ,CAClE,CACR,CAAC,CAAC,CAAC,CACF;gBACG,QAAQ,IAAI,OAAO,CAAC,IAAI,IAAI,CAC3B,8BAAM,SAAS,EAAC,6BAA6B,IAAE,OAAO,CAAC,IAAI,CAAQ,CACpE;gBACA,SAAS,IAAI,OAAO,CAAC,KAAK,IAAI,CAC7B,8BAAM,SAAS,EAAE,YAAY,IAAG,OAAO,CAAC,KAAK,CAAQ,CACtD,CACA,CACJ,CACM,CACV,CAAC;QACJ,CAAC,CAAC,CACE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EACV,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/SegmentedControl/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Button } from './Button/index.js';
|
|
2
|
+
export type { ButtonProps, ButtonSize, ButtonType } from './Button/index.js';
|
|
3
|
+
export { InputField } from './InputField/index.js';
|
|
4
|
+
export type { InputFieldProps, InputFieldState } from './InputField/index.js';
|
|
5
|
+
export { InlineMessage } from './InlineMessage/index.js';
|
|
6
|
+
export type { InlineMessageBreakpoint, InlineMessageProps, InlineMessageStatus, } from './InlineMessage/index.js';
|
|
7
|
+
export { SegmentedControl } from './SegmentedControl/index.js';
|
|
8
|
+
export type { Segment, SegmentedControlContentMode, SegmentedControlProps, SegmentedControlType, } from './SegmentedControl/index.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,YAAY,EACV,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,YAAY,EACV,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @ckwag/elements — public exports
|
|
2
|
+
export { Button } from './Button/index.js';
|
|
3
|
+
export { InputField } from './InputField/index.js';
|
|
4
|
+
export { InlineMessage } from './InlineMessage/index.js';
|
|
5
|
+
export { SegmentedControl } from './SegmentedControl/index.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Button } from '../Button/index.js';
|
|
2
|
+
export type { ButtonProps, ButtonSize, ButtonType } from '../Button/index.js';
|
|
3
|
+
export { InputField } from '../InputField/index.js';
|
|
4
|
+
export type { InputFieldProps, InputFieldState } from '../InputField/index.js';
|
|
5
|
+
export { InlineMessage } from '../InlineMessage/index.js';
|
|
6
|
+
export type { InlineMessageBreakpoint, InlineMessageProps, InlineMessageStatus, } from '../InlineMessage/index.js';
|
|
7
|
+
export { SegmentedControl } from '../SegmentedControl/index.js';
|
|
8
|
+
export type { Segment, SegmentedControlContentMode, SegmentedControlProps, SegmentedControlType, } from '../SegmentedControl/index.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,YAAY,EACV,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,YAAY,EACV,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @ckwag/elements/react — re-exports all React components
|
|
2
|
+
export { Button } from '../Button/index.js';
|
|
3
|
+
export { InputField } from '../InputField/index.js';
|
|
4
|
+
export { InlineMessage } from '../InlineMessage/index.js';
|
|
5
|
+
export { SegmentedControl } from '../SegmentedControl/index.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/styles.css
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ckwag/elements",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "CKW Elements UI Components",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/CKWAG/ckw-elements.git",
|
|
10
|
+
"directory": "packages/components"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://ckwag.github.io/ckw-elements/",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/CKWAG/ckw-elements/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"ckw",
|
|
18
|
+
"design-system",
|
|
19
|
+
"react",
|
|
20
|
+
"components"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"style": "./dist/styles.css",
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"**/*.css"
|
|
28
|
+
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./styles.css": "./dist/styles.css",
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@ckwag/elements-icons": "0.0.1",
|
|
46
|
+
"@ckwag/elements-tokens": "0.0.1"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=18 <20",
|
|
50
|
+
"react-dom": ">=18 <20"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/react": "^19.0.0",
|
|
54
|
+
"@types/react-dom": "^19.0.0",
|
|
55
|
+
"react": "^19.0.0",
|
|
56
|
+
"react-dom": "^19.0.0",
|
|
57
|
+
"typescript": "^5.9.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"prebuild": "pnpm --filter @ckwag/elements-icons run build",
|
|
61
|
+
"build": "node build-components.mjs",
|
|
62
|
+
"lint": "echo 'lint step — will be configured with eslint'"
|
|
63
|
+
}
|
|
64
|
+
}
|