@astryxdesign/core 0.4.4 → 0.4.5-canary.1fdecb1
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/CHANGELOG.md +40 -0
- package/dist/BottomSheet/BottomSheet.d.ts +11 -2
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +4 -0
- package/dist/BottomSheet/BottomSheetPanel.d.ts +5 -2
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +65 -15
- package/dist/BottomSheet/index.d.ts +1 -1
- package/dist/BottomSheet/index.d.ts.map +1 -1
- package/dist/BottomSheet/snapOffsets.d.ts +57 -20
- package/dist/BottomSheet/snapOffsets.d.ts.map +1 -1
- package/dist/BottomSheet/snapOffsets.js +106 -30
- package/dist/BottomSheet/useSheetGestures.d.ts +13 -8
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +160 -64
- package/dist/Calendar/Calendar.d.ts +17 -0
- package/dist/Calendar/Calendar.d.ts.map +1 -1
- package/dist/Calendar/Calendar.js +34 -3
- package/dist/Calendar/getStandaloneShortWeekdayNames.d.ts +14 -0
- package/dist/Calendar/getStandaloneShortWeekdayNames.d.ts.map +1 -0
- package/dist/Calendar/getStandaloneShortWeekdayNames.js +26 -0
- package/dist/Calendar/hooks/useCalendarConstraints.d.ts +22 -1
- package/dist/Calendar/hooks/useCalendarConstraints.d.ts.map +1 -1
- package/dist/Calendar/hooks/useCalendarConstraints.js +26 -4
- package/dist/Calendar/hooks/useCalendarDays.d.ts.map +1 -1
- package/dist/Calendar/hooks/useCalendarDays.js +14 -10
- package/dist/Calendar/standaloneShortWeekdayNames.generated.d.ts +47 -0
- package/dist/Calendar/standaloneShortWeekdayNames.generated.d.ts.map +1 -0
- package/dist/Calendar/standaloneShortWeekdayNames.generated.js +40 -0
- package/dist/Center/Center.d.ts +23 -1
- package/dist/Center/Center.d.ts.map +1 -1
- package/dist/Center/Center.js +12 -6
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +9 -0
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +6 -1
- package/dist/DateInput/DateInput.d.ts.map +1 -1
- package/dist/DateInput/DateInput.js +6 -1
- package/dist/DateRangeInput/DateRangeInput.d.ts +23 -1
- package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
- package/dist/DateRangeInput/DateRangeInput.js +38 -3
- package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
- package/dist/DateTimeInput/DateTimeInput.js +7 -2
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +3 -3
- package/dist/Field/FieldLabel.d.ts +2 -1
- package/dist/Field/FieldLabel.d.ts.map +1 -1
- package/dist/Field/FieldLabel.js +21 -3
- package/dist/Field/InputClearButton.d.ts +2 -1
- package/dist/Field/InputClearButton.d.ts.map +1 -1
- package/dist/Field/InputClearButton.js +6 -1
- package/dist/FormLayout/FormLayout.d.ts +24 -2
- package/dist/FormLayout/FormLayout.d.ts.map +1 -1
- package/dist/FormLayout/FormLayout.js +7 -2
- package/dist/FormLayout/FormLayoutContext.d.ts +15 -2
- package/dist/FormLayout/FormLayoutContext.d.ts.map +1 -1
- package/dist/FormLayout/FormLayoutContext.js +19 -4
- package/dist/FormLayout/index.d.ts +1 -1
- package/dist/FormLayout/index.d.ts.map +1 -1
- package/dist/Item/Item.d.ts +9 -1
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +45 -7
- package/dist/Layer/useLayer.d.ts.map +1 -1
- package/dist/Layer/useLayer.js +3 -2
- package/dist/Layout/container.stylex.d.ts +4 -2
- package/dist/Layout/container.stylex.d.ts.map +1 -1
- package/dist/Layout/container.stylex.js +19 -11
- package/dist/Layout/index.d.ts +1 -0
- package/dist/Layout/index.d.ts.map +1 -1
- package/dist/Layout/index.js +4 -0
- package/dist/Layout/padding.stylex.d.ts +315 -12
- package/dist/Layout/padding.stylex.d.ts.map +1 -1
- package/dist/Layout/padding.stylex.js +389 -12
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +2 -1
- package/dist/Markdown/Markdown.d.ts +8 -0
- package/dist/Markdown/Markdown.d.ts.map +1 -1
- package/dist/Markdown/Markdown.js +31 -3
- package/dist/Markdown/parser.d.ts +14 -2
- package/dist/Markdown/parser.d.ts.map +1 -1
- package/dist/Markdown/parser.js +50 -2
- package/dist/MobileNav/MobileNav.d.ts +1 -0
- package/dist/MobileNav/MobileNav.d.ts.map +1 -1
- package/dist/MobileNav/MobileNav.js +24 -6
- package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
- package/dist/MultiSelector/MultiSelector.js +6 -1
- package/dist/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/NumberInput/NumberInput.js +36 -3
- package/dist/Outline/parseOutlineFromMarkdown.d.ts +2 -0
- package/dist/Outline/parseOutlineFromMarkdown.d.ts.map +1 -1
- package/dist/Outline/parseOutlineFromMarkdown.js +5 -31
- package/dist/RadioList/RadioList.d.ts.map +1 -1
- package/dist/RadioList/RadioList.js +12 -1
- package/dist/Resizable/ResizeHandle.d.ts.map +1 -1
- package/dist/Resizable/ResizeHandle.js +3 -3
- package/dist/Section/Section.d.ts +36 -1
- package/dist/Section/Section.d.ts.map +1 -1
- package/dist/Section/Section.js +12 -2
- package/dist/Selector/Selector.d.ts +26 -1
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +93 -15
- package/dist/Selector/SelectorOption.d.ts +14 -1
- package/dist/Selector/SelectorOption.d.ts.map +1 -1
- package/dist/Selector/SelectorOption.js +6 -0
- package/dist/Selector/SelectorRowLayoutContext.d.ts +8 -0
- package/dist/Selector/SelectorRowLayoutContext.d.ts.map +1 -0
- package/dist/Selector/SelectorRowLayoutContext.js +27 -0
- package/dist/Selector/types.d.ts +1 -0
- package/dist/Selector/types.d.ts.map +1 -1
- package/dist/Slider/Slider.d.ts.map +1 -1
- package/dist/Slider/Slider.js +2 -2
- package/dist/Stack/Stack.d.ts +23 -1
- package/dist/Stack/Stack.d.ts.map +1 -1
- package/dist/Stack/Stack.js +12 -6
- package/dist/StatusDot/StatusDot.d.ts +43 -3
- package/dist/StatusDot/StatusDot.d.ts.map +1 -1
- package/dist/StatusDot/StatusDot.js +42 -5
- package/dist/Switch/Switch.d.ts.map +1 -1
- package/dist/Switch/Switch.js +9 -0
- package/dist/Table/plugins/rowExpansion/useTableRowExpansion.d.ts.map +1 -1
- package/dist/Table/plugins/rowExpansion/useTableRowExpansion.js +7 -2
- package/dist/TextArea/TextArea.d.ts.map +1 -1
- package/dist/TextArea/TextArea.js +6 -1
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +6 -1
- package/dist/TimeInput/TimeInput.d.ts.map +1 -1
- package/dist/TimeInput/TimeInput.js +6 -1
- package/dist/astryx.css +40 -21
- package/dist/hooks/scrollbarGutter.d.ts +28 -0
- package/dist/hooks/scrollbarGutter.d.ts.map +1 -0
- package/dist/hooks/scrollbarGutter.js +103 -0
- package/dist/hooks/useResolvedRequired.d.ts +19 -0
- package/dist/hooks/useResolvedRequired.d.ts.map +1 -0
- package/dist/hooks/useResolvedRequired.js +40 -0
- package/dist/hooks/useScrollLock.d.ts +4 -0
- package/dist/hooks/useScrollLock.d.ts.map +1 -1
- package/dist/hooks/useScrollLock.js +13 -1
- package/dist/theme/derivedVarRegistry.d.ts.map +1 -1
- package/dist/theme/derivedVarRegistry.js +7 -0
- package/dist/theme/generateThemeRules.d.ts.map +1 -1
- package/dist/theme/generateThemeRules.js +37 -4
- package/dist/utils/plainDate.d.ts +6 -0
- package/dist/utils/plainDate.d.ts.map +1 -1
- package/dist/utils/plainDate.js +12 -0
- package/locales/af-ZA.json +958 -0
- package/locales/ar-SA.json +998 -0
- package/locales/ca-ES.json +974 -0
- package/locales/cs-CZ.json +990 -0
- package/locales/da-DK.json +966 -0
- package/locales/de-DE.json +966 -0
- package/locales/el-GR.json +990 -0
- package/locales/en.json +8 -0
- package/locales/es-ES.json +978 -0
- package/locales/fi-FI.json +990 -0
- package/locales/fr-FR.json +928 -0
- package/locales/he-IL.json +990 -0
- package/locales/hu-HU.json +990 -0
- package/locales/it-IT.json +978 -0
- package/locales/ja-JP.json +998 -0
- package/locales/ko-KR.json +990 -0
- package/locales/nl-NL.json +954 -0
- package/locales/no-NO.json +978 -0
- package/locales/pl-PL.json +982 -0
- package/locales/pseudo.json +6 -0
- package/locales/pt-BR.json +982 -0
- package/locales/pt-PT.json +982 -0
- package/locales/ro-RO.json +982 -0
- package/locales/ru-RU.json +990 -0
- package/locales/sr-SP.json +990 -0
- package/locales/sv-SE.json +986 -0
- package/locales/tr-TR.json +990 -0
- package/locales/uk-UA.json +990 -0
- package/locales/vi-VN.json +986 -0
- package/locales/zh-CN.json +998 -0
- package/locales/zh-TW.json +998 -0
- package/package.json +3 -3
- package/src/BottomSheet/BottomSheet.doc.mjs +36 -3
- package/src/BottomSheet/BottomSheet.test.tsx +177 -2
- package/src/BottomSheet/BottomSheet.tsx +16 -2
- package/src/BottomSheet/BottomSheetPanel.test.tsx +41 -0
- package/src/BottomSheet/BottomSheetPanel.tsx +95 -15
- package/src/BottomSheet/index.ts +5 -1
- package/src/BottomSheet/snapOffsets.test.ts +114 -47
- package/src/BottomSheet/snapOffsets.ts +119 -33
- package/src/BottomSheet/useSheetGestures.test.ts +113 -15
- package/src/BottomSheet/useSheetGestures.ts +196 -100
- package/src/Calendar/Calendar.doc.mjs +16 -0
- package/src/Calendar/Calendar.test.tsx +137 -0
- package/src/Calendar/Calendar.tsx +65 -2
- package/src/Calendar/getStandaloneShortWeekdayNames.test.ts +54 -0
- package/src/Calendar/getStandaloneShortWeekdayNames.ts +38 -0
- package/src/Calendar/hooks/useCalendarConstraints.ts +54 -3
- package/src/Calendar/hooks/useCalendarDays.ts +13 -10
- package/src/Calendar/standaloneShortWeekdayNames.generated.ts +50 -0
- package/src/Center/Center.doc.mjs +48 -0
- package/src/Center/Center.test.tsx +158 -0
- package/src/Center/Center.tsx +50 -9
- package/src/CheckboxInput/CheckboxInput.tsx +6 -0
- package/src/ComplexSelector/ComplexSelector.tsx +3 -1
- package/src/DateInput/DateInput.tsx +3 -1
- package/src/DateRangeInput/DateRangeInput.doc.mjs +16 -0
- package/src/DateRangeInput/DateRangeInput.test.tsx +81 -1
- package/src/DateRangeInput/DateRangeInput.tsx +72 -1
- package/src/DateTimeInput/DateTimeInput.tsx +4 -2
- package/src/Dialog/Dialog.test.tsx +24 -0
- package/src/Dialog/Dialog.tsx +3 -0
- package/src/Field/Field.doc.mjs +1 -0
- package/src/Field/FieldLabel.tsx +20 -4
- package/src/Field/InputClearButton.test.tsx +25 -0
- package/src/Field/InputClearButton.tsx +4 -1
- package/src/FormLayout/FormLayout.doc.mjs +13 -0
- package/src/FormLayout/FormLayout.test.tsx +181 -4
- package/src/FormLayout/FormLayout.tsx +33 -2
- package/src/FormLayout/FormLayoutContext.ts +22 -7
- package/src/FormLayout/index.ts +1 -1
- package/src/Item/Item.doc.mjs +1 -0
- package/src/Item/Item.test.tsx +50 -0
- package/src/Item/Item.tsx +40 -1
- package/src/Layer/useLayer.tsx +13 -2
- package/src/Layout/Layout.doc.mjs +18 -0
- package/src/Layout/container.stylex.ts +11 -3
- package/src/Layout/index.ts +4 -0
- package/src/Layout/overlayPaddingReset.test.tsx +222 -0
- package/src/Layout/padding.stylex.ts +192 -12
- package/src/Lightbox/Lightbox.tsx +2 -1
- package/src/Markdown/Markdown.doc.mjs +3 -0
- package/src/Markdown/Markdown.test.tsx +78 -0
- package/src/Markdown/Markdown.tsx +41 -1
- package/src/Markdown/parser.ts +60 -2
- package/src/MobileNav/MobileNav.tsx +61 -5
- package/src/MobileNav/MobileNavEntryAnimation.test.tsx +212 -0
- package/src/MobileNav/MobileNavScrollbarGutter.test.tsx +109 -0
- package/src/MultiSelector/MultiSelector.tsx +3 -1
- package/src/NumberInput/NumberInput.doc.mjs +24 -0
- package/src/NumberInput/NumberInput.test.tsx +138 -0
- package/src/NumberInput/NumberInput.tsx +43 -5
- package/src/Outline/Outline.doc.mjs +2 -0
- package/src/Outline/parseOutlineFromMarkdown.ts +10 -40
- package/src/RadioList/RadioList.tsx +9 -1
- package/src/Resizable/ResizeHandle.test.tsx +22 -0
- package/src/Resizable/ResizeHandle.tsx +9 -3
- package/src/Section/Section.doc.mjs +55 -0
- package/src/Section/Section.test.tsx +201 -4
- package/src/Section/Section.tsx +69 -0
- package/src/Selector/Selector.doc.mjs +16 -2
- package/src/Selector/Selector.test.tsx +524 -0
- package/src/Selector/Selector.tsx +161 -17
- package/src/Selector/SelectorOption.doc.mjs +7 -0
- package/src/Selector/SelectorOption.tsx +21 -0
- package/src/Selector/SelectorRowLayoutContext.ts +32 -0
- package/src/Selector/types.ts +4 -4
- package/src/Slider/Slider.tsx +10 -0
- package/src/Stack/Stack.doc.mjs +72 -0
- package/src/Stack/Stack.test.tsx +156 -0
- package/src/Stack/Stack.tsx +50 -8
- package/src/StatusDot/StatusDot.doc.mjs +13 -0
- package/src/StatusDot/StatusDot.test.tsx +115 -8
- package/src/StatusDot/StatusDot.tsx +74 -9
- package/src/Switch/Switch.tsx +6 -0
- package/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx +20 -2
- package/src/TextArea/TextArea.tsx +3 -1
- package/src/TextInput/TextInput.tsx +3 -1
- package/src/TimeInput/TimeInput.tsx +3 -1
- package/src/hooks/scrollbarGutter.test.ts +167 -0
- package/src/hooks/scrollbarGutter.ts +121 -0
- package/src/hooks/useResolvedRequired.ts +42 -0
- package/src/hooks/useScrollLock.doc.mjs +4 -4
- package/src/hooks/useScrollLock.test.ts +73 -0
- package/src/hooks/useScrollLock.ts +14 -0
- package/src/theme/derivedVarRegistry.test.ts +14 -3
- package/src/theme/derivedVarRegistry.ts +4 -0
- package/src/theme/generateThemeRules.test.ts +79 -0
- package/src/theme/generateThemeRules.ts +49 -4
- package/src/utils/plainDate.test.ts +50 -0
- package/src/utils/plainDate.ts +12 -0
package/src/Stack/Stack.test.tsx
CHANGED
|
@@ -13,6 +13,22 @@ import {describe, it, expect, vi} from 'vitest';
|
|
|
13
13
|
import {render, screen} from '@testing-library/react';
|
|
14
14
|
import {Stack} from './Stack';
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* The functional class output, as an order-insensitive set. StyleX's dev
|
|
18
|
+
* runtime also emits readable debug classes naming the style object a
|
|
19
|
+
* declaration came from ("padding__paddingBlockStyles.2"); those record
|
|
20
|
+
* provenance rather than applied CSS and survive even when the declaration
|
|
21
|
+
* they name loses a merge, so they are dropped here.
|
|
22
|
+
*/
|
|
23
|
+
function classSet(el: HTMLElement): Set<string> {
|
|
24
|
+
return new Set(
|
|
25
|
+
el.className
|
|
26
|
+
.split(' ')
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.filter(c => !c.includes('__') && !c.includes('.')),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
16
32
|
describe('Stack', () => {
|
|
17
33
|
it('defaults to vertical direction', () => {
|
|
18
34
|
render(
|
|
@@ -314,4 +330,144 @@ describe('Stack', () => {
|
|
|
314
330
|
const withScroll = screen.getByTestId('stack').className;
|
|
315
331
|
expect(withScroll).not.toBe(withoutScroll);
|
|
316
332
|
});
|
|
333
|
+
|
|
334
|
+
it('applies a class when paddingBlockStart is set on its own', () => {
|
|
335
|
+
const {rerender} = render(
|
|
336
|
+
<Stack data-testid="stack">
|
|
337
|
+
<div>Content</div>
|
|
338
|
+
</Stack>,
|
|
339
|
+
);
|
|
340
|
+
const baseline = screen.getByTestId('stack').className;
|
|
341
|
+
rerender(
|
|
342
|
+
<Stack paddingBlockStart={2} data-testid="stack">
|
|
343
|
+
<div>Content</div>
|
|
344
|
+
</Stack>,
|
|
345
|
+
);
|
|
346
|
+
expect(screen.getByTestId('stack').className).not.toBe(baseline);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('lets paddingBlockStart/paddingBlockEnd override only their own edge', () => {
|
|
350
|
+
const {rerender} = render(
|
|
351
|
+
<Stack padding={4} paddingBlockStart={2} data-testid="stack">
|
|
352
|
+
<div>Content</div>
|
|
353
|
+
</Stack>,
|
|
354
|
+
);
|
|
355
|
+
const perEdge = classSet(screen.getByTestId('stack'));
|
|
356
|
+
rerender(
|
|
357
|
+
<Stack
|
|
358
|
+
paddingInline={4}
|
|
359
|
+
paddingBlockStart={2}
|
|
360
|
+
paddingBlockEnd={4}
|
|
361
|
+
data-testid="stack">
|
|
362
|
+
<div>Content</div>
|
|
363
|
+
</Stack>,
|
|
364
|
+
);
|
|
365
|
+
expect(perEdge).toEqual(classSet(screen.getByTestId('stack')));
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('gives paddingBlockEnd precedence over paddingBlock', () => {
|
|
369
|
+
const {rerender} = render(
|
|
370
|
+
<Stack paddingBlock={6} paddingBlockEnd={0} data-testid="stack">
|
|
371
|
+
<div>Content</div>
|
|
372
|
+
</Stack>,
|
|
373
|
+
);
|
|
374
|
+
const overridden = classSet(screen.getByTestId('stack'));
|
|
375
|
+
rerender(
|
|
376
|
+
<Stack paddingBlockStart={6} paddingBlockEnd={0} data-testid="stack">
|
|
377
|
+
<div>Content</div>
|
|
378
|
+
</Stack>,
|
|
379
|
+
);
|
|
380
|
+
expect(overridden).toEqual(classSet(screen.getByTestId('stack')));
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('leaves padding/paddingBlock output unchanged when no edge prop is set', () => {
|
|
384
|
+
const {rerender} = render(
|
|
385
|
+
<Stack padding={3} data-testid="stack">
|
|
386
|
+
<div>Content</div>
|
|
387
|
+
</Stack>,
|
|
388
|
+
);
|
|
389
|
+
const uniform = classSet(screen.getByTestId('stack'));
|
|
390
|
+
rerender(
|
|
391
|
+
<Stack paddingInline={3} paddingBlock={3} data-testid="stack">
|
|
392
|
+
<div>Content</div>
|
|
393
|
+
</Stack>,
|
|
394
|
+
);
|
|
395
|
+
expect(uniform).toEqual(classSet(screen.getByTestId('stack')));
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it('applies a class when paddingInlineStart is set on its own', () => {
|
|
399
|
+
const {rerender} = render(
|
|
400
|
+
<Stack data-testid="stack">
|
|
401
|
+
<div>Content</div>
|
|
402
|
+
</Stack>,
|
|
403
|
+
);
|
|
404
|
+
const baseline = screen.getByTestId('stack').className;
|
|
405
|
+
rerender(
|
|
406
|
+
<Stack paddingInlineStart={2} data-testid="stack">
|
|
407
|
+
<div>Content</div>
|
|
408
|
+
</Stack>,
|
|
409
|
+
);
|
|
410
|
+
expect(screen.getByTestId('stack').className).not.toBe(baseline);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('lets paddingInlineStart/paddingInlineEnd override only their own edge', () => {
|
|
414
|
+
const {rerender} = render(
|
|
415
|
+
<Stack padding={4} paddingInlineStart={2} data-testid="stack">
|
|
416
|
+
<div>Content</div>
|
|
417
|
+
</Stack>,
|
|
418
|
+
);
|
|
419
|
+
const perEdge = classSet(screen.getByTestId('stack'));
|
|
420
|
+
rerender(
|
|
421
|
+
<Stack
|
|
422
|
+
paddingInlineStart={2}
|
|
423
|
+
paddingInlineEnd={4}
|
|
424
|
+
paddingBlock={4}
|
|
425
|
+
data-testid="stack">
|
|
426
|
+
<div>Content</div>
|
|
427
|
+
</Stack>,
|
|
428
|
+
);
|
|
429
|
+
expect(perEdge).toEqual(classSet(screen.getByTestId('stack')));
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it('gives paddingInlineEnd precedence over paddingInline', () => {
|
|
433
|
+
const {rerender} = render(
|
|
434
|
+
<Stack paddingInline={6} paddingInlineEnd={0} data-testid="stack">
|
|
435
|
+
<div>Content</div>
|
|
436
|
+
</Stack>,
|
|
437
|
+
);
|
|
438
|
+
const overridden = classSet(screen.getByTestId('stack'));
|
|
439
|
+
rerender(
|
|
440
|
+
<Stack paddingInlineStart={6} paddingInlineEnd={0} data-testid="stack">
|
|
441
|
+
<div>Content</div>
|
|
442
|
+
</Stack>,
|
|
443
|
+
);
|
|
444
|
+
expect(overridden).toEqual(classSet(screen.getByTestId('stack')));
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('resolves all four edges independently', () => {
|
|
448
|
+
// One prop per edge, each a different step: the four-edge spelling and the
|
|
449
|
+
// shorthand-plus-overrides spelling must agree.
|
|
450
|
+
const {rerender} = render(
|
|
451
|
+
<Stack
|
|
452
|
+
paddingInlineStart={1}
|
|
453
|
+
paddingInlineEnd={2}
|
|
454
|
+
paddingBlockStart={3}
|
|
455
|
+
paddingBlockEnd={4}
|
|
456
|
+
data-testid="stack">
|
|
457
|
+
<div>Content</div>
|
|
458
|
+
</Stack>,
|
|
459
|
+
);
|
|
460
|
+
const explicit = classSet(screen.getByTestId('stack'));
|
|
461
|
+
rerender(
|
|
462
|
+
<Stack
|
|
463
|
+
padding={4}
|
|
464
|
+
paddingInlineStart={1}
|
|
465
|
+
paddingInlineEnd={2}
|
|
466
|
+
paddingBlockStart={3}
|
|
467
|
+
data-testid="stack">
|
|
468
|
+
<div>Content</div>
|
|
469
|
+
</Stack>,
|
|
470
|
+
);
|
|
471
|
+
expect(explicit).toEqual(classSet(screen.getByTestId('stack')));
|
|
472
|
+
});
|
|
317
473
|
});
|
package/src/Stack/Stack.tsx
CHANGED
|
@@ -25,8 +25,10 @@ import {
|
|
|
25
25
|
} from './stack.stylex';
|
|
26
26
|
import type {SizeValue} from '../utils/types';
|
|
27
27
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
paddingInlineStartStyles,
|
|
29
|
+
paddingInlineEndStyles,
|
|
30
|
+
paddingBlockStartStyles,
|
|
31
|
+
paddingBlockEndStyles,
|
|
30
32
|
} from '../Layout/padding.stylex';
|
|
31
33
|
import {mergeProps} from '../utils';
|
|
32
34
|
import {themeProps} from '../utils/themeProps';
|
|
@@ -140,12 +142,38 @@ export interface StackProps extends BaseProps<HTMLElement> {
|
|
|
140
142
|
*/
|
|
141
143
|
paddingInline?: SpacingStep;
|
|
142
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Inline-start padding, using the spacing scale. Logical: the left edge in
|
|
147
|
+
* LTR, the right edge in RTL.
|
|
148
|
+
* Overrides `paddingInline` and `padding` on that edge only.
|
|
149
|
+
*/
|
|
150
|
+
paddingInlineStart?: SpacingStep;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Inline-end padding, using the spacing scale. Logical: the right edge in
|
|
154
|
+
* LTR, the left edge in RTL.
|
|
155
|
+
* Overrides `paddingInline` and `padding` on that edge only.
|
|
156
|
+
*/
|
|
157
|
+
paddingInlineEnd?: SpacingStep;
|
|
158
|
+
|
|
143
159
|
/**
|
|
144
160
|
* Block (vertical) padding, using the spacing scale.
|
|
145
161
|
* Overrides `padding` on the block axis when both are set.
|
|
146
162
|
*/
|
|
147
163
|
paddingBlock?: SpacingStep;
|
|
148
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Block-start (top) padding, using the spacing scale.
|
|
167
|
+
* Overrides `paddingBlock` and `padding` on that edge only.
|
|
168
|
+
*/
|
|
169
|
+
paddingBlockStart?: SpacingStep;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Block-end (bottom) padding, using the spacing scale.
|
|
173
|
+
* Overrides `paddingBlock` and `padding` on that edge only.
|
|
174
|
+
*/
|
|
175
|
+
paddingBlockEnd?: SpacingStep;
|
|
176
|
+
|
|
149
177
|
/**
|
|
150
178
|
* Enables scrollable overflow (`overflow: auto`) for the stack.
|
|
151
179
|
*
|
|
@@ -211,7 +239,11 @@ export function Stack({
|
|
|
211
239
|
gap,
|
|
212
240
|
padding,
|
|
213
241
|
paddingInline,
|
|
242
|
+
paddingInlineStart,
|
|
243
|
+
paddingInlineEnd,
|
|
214
244
|
paddingBlock,
|
|
245
|
+
paddingBlockStart,
|
|
246
|
+
paddingBlockEnd,
|
|
215
247
|
isScrollable,
|
|
216
248
|
width,
|
|
217
249
|
height,
|
|
@@ -242,10 +274,14 @@ export function Stack({
|
|
|
242
274
|
? (resolvedVAlign as StackCrossAlignment | undefined)
|
|
243
275
|
: (resolvedHAlign as StackCrossAlignment | undefined);
|
|
244
276
|
|
|
245
|
-
// Resolve padding to per-
|
|
246
|
-
//
|
|
247
|
-
const
|
|
248
|
-
|
|
277
|
+
// Resolve padding to per-edge values. Most specific wins, per edge:
|
|
278
|
+
// edge prop -> axis prop -> `padding`.
|
|
279
|
+
const resolvedPaddingInlineStart =
|
|
280
|
+
paddingInlineStart ?? paddingInline ?? padding;
|
|
281
|
+
const resolvedPaddingInlineEnd = paddingInlineEnd ?? paddingInline ?? padding;
|
|
282
|
+
const resolvedPaddingBlockStart =
|
|
283
|
+
paddingBlockStart ?? paddingBlock ?? padding;
|
|
284
|
+
const resolvedPaddingBlockEnd = paddingBlockEnd ?? paddingBlock ?? padding;
|
|
249
285
|
|
|
250
286
|
const stylexProps = stylex.props(
|
|
251
287
|
...stack({
|
|
@@ -255,8 +291,14 @@ export function Stack({
|
|
|
255
291
|
gap,
|
|
256
292
|
wrap,
|
|
257
293
|
}),
|
|
258
|
-
|
|
259
|
-
|
|
294
|
+
resolvedPaddingInlineStart != null &&
|
|
295
|
+
paddingInlineStartStyles[resolvedPaddingInlineStart],
|
|
296
|
+
resolvedPaddingInlineEnd != null &&
|
|
297
|
+
paddingInlineEndStyles[resolvedPaddingInlineEnd],
|
|
298
|
+
resolvedPaddingBlockStart != null &&
|
|
299
|
+
paddingBlockStartStyles[resolvedPaddingBlockStart],
|
|
300
|
+
resolvedPaddingBlockEnd != null &&
|
|
301
|
+
paddingBlockEndStyles[resolvedPaddingBlockEnd],
|
|
260
302
|
isScrollable && overflowStyles.scrollable,
|
|
261
303
|
xstyle,
|
|
262
304
|
);
|
|
@@ -33,6 +33,12 @@ export const docs = {
|
|
|
33
33
|
description:
|
|
34
34
|
'Tooltip text shown on hover to explain the status meaning.',
|
|
35
35
|
},
|
|
36
|
+
{
|
|
37
|
+
name: 'icon',
|
|
38
|
+
type: 'ReactNode',
|
|
39
|
+
description:
|
|
40
|
+
'Optional icon rendered centered inside the dot, painted in currentColor (the variant\'s ink). Gives the status a non-color mark, so use a different icon per status. Booleans and empty strings are ignored, so `cond && <Icon />` is safe. Same contract as AvatarStatusDot.',
|
|
41
|
+
},
|
|
36
42
|
{
|
|
37
43
|
name: 'xstyle',
|
|
38
44
|
type: 'StyleXStyles',
|
|
@@ -84,6 +90,12 @@ export const docsZh = {
|
|
|
84
90
|
'启用脉冲动画;尊重 prefers-reduced-motion: reduce 设置。',
|
|
85
91
|
default: 'false',
|
|
86
92
|
},
|
|
93
|
+
{
|
|
94
|
+
name: 'icon',
|
|
95
|
+
type: 'ReactNode',
|
|
96
|
+
description:
|
|
97
|
+
'可选图标,居中渲染于圆点内,以 currentColor(变体的前景色)着色。为状态提供非颜色标记,请为每个状态使用不同图标。布尔值和空字符串会被忽略,因此 `cond && <Icon />` 是安全的。与 AvatarStatusDot 的契约一致。',
|
|
98
|
+
},
|
|
87
99
|
{
|
|
88
100
|
name: 'xstyle',
|
|
89
101
|
type: 'StyleXStyles',
|
|
@@ -132,6 +144,7 @@ export const docsDense = {
|
|
|
132
144
|
label: 'Accessible label via aria-label.',
|
|
133
145
|
isPulsing: 'Pulse animation; respects prefers-reduced-motion: reduce.',
|
|
134
146
|
tooltip: 'Tooltip text on hover to explain status meaning.',
|
|
147
|
+
icon: 'Optional ReactNode rendered centered in the dot (currentColor ink); a non-color mark for the status, use a different icon per status. Booleans/empty strings ignored (safe for cond && <Icon/>). Same contract as AvatarStatusDot.',
|
|
135
148
|
xstyle: 'StyleX layout styles; must be stylex.create() value.',
|
|
136
149
|
},
|
|
137
150
|
};
|
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import {describe, it, expect} from 'vitest';
|
|
4
4
|
import {render, screen} from '@testing-library/react';
|
|
5
|
+
import * as stylex from '@stylexjs/stylex';
|
|
6
|
+
import {colorVars} from '../theme/tokens.stylex';
|
|
5
7
|
import {StatusDot} from './StatusDot';
|
|
6
8
|
|
|
9
|
+
/** Renders a StatusDot and returns its root element. */
|
|
10
|
+
function renderDot(props: React.ComponentProps<typeof StatusDot>) {
|
|
11
|
+
render(<StatusDot {...props} />);
|
|
12
|
+
return screen.getByRole('img', {name: props.label});
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
describe('StatusDot', () => {
|
|
8
16
|
it('renders with role="img" and aria-label', () => {
|
|
9
17
|
render(<StatusDot variant="success" label="Online" />);
|
|
@@ -27,9 +35,7 @@ describe('StatusDot', () => {
|
|
|
27
35
|
] as const;
|
|
28
36
|
|
|
29
37
|
for (const variant of variants) {
|
|
30
|
-
const {unmount} = render(
|
|
31
|
-
<StatusDot variant={variant} label={variant} />,
|
|
32
|
-
);
|
|
38
|
+
const {unmount} = render(<StatusDot variant={variant} label={variant} />);
|
|
33
39
|
expect(screen.getByRole('img', {name: variant})).toBeInTheDocument();
|
|
34
40
|
unmount();
|
|
35
41
|
}
|
|
@@ -49,11 +55,7 @@ describe('StatusDot', () => {
|
|
|
49
55
|
|
|
50
56
|
it('supports data-testid', () => {
|
|
51
57
|
render(
|
|
52
|
-
<StatusDot
|
|
53
|
-
variant="success"
|
|
54
|
-
label="Online"
|
|
55
|
-
data-testid="status-dot"
|
|
56
|
-
/>,
|
|
58
|
+
<StatusDot variant="success" label="Online" data-testid="status-dot" />,
|
|
57
59
|
);
|
|
58
60
|
expect(screen.getByTestId('status-dot')).toBeInTheDocument();
|
|
59
61
|
});
|
|
@@ -81,4 +83,109 @@ describe('StatusDot', () => {
|
|
|
81
83
|
const dot = screen.getByRole('img', {name: 'Online'});
|
|
82
84
|
expect(dot).toBeInTheDocument();
|
|
83
85
|
});
|
|
86
|
+
|
|
87
|
+
it('renders every variant as a plain childless dot by default (design review #4373)', () => {
|
|
88
|
+
// The dot is deliberately a colour-only signal by default — no built-in
|
|
89
|
+
// per-variant glyph. Making the status accessible in context (label,
|
|
90
|
+
// icon, or an accessible alternative) is the builder's responsibility;
|
|
91
|
+
// see the usage guidance.
|
|
92
|
+
const variants = [
|
|
93
|
+
'success',
|
|
94
|
+
'warning',
|
|
95
|
+
'error',
|
|
96
|
+
'accent',
|
|
97
|
+
'neutral',
|
|
98
|
+
] as const;
|
|
99
|
+
for (const variant of variants) {
|
|
100
|
+
const dot = renderDot({variant, label: `plain-${variant}`});
|
|
101
|
+
expect(dot.childElementCount, variant).toBe(0);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('custom icon (parity with AvatarStatusDot)', () => {
|
|
106
|
+
const ICON_TESTID = 'custom-icon';
|
|
107
|
+
function Icon() {
|
|
108
|
+
return <svg data-testid={ICON_TESTID} />;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
it('renders a provided icon inside the dot', () => {
|
|
112
|
+
renderDot({variant: 'success', label: 'Verified', icon: <Icon />});
|
|
113
|
+
expect(screen.getByTestId(ICON_TESTID)).toBeInTheDocument();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('hides the icon wrapper from assistive tech (the label carries the status)', () => {
|
|
117
|
+
renderDot({variant: 'success', label: 'Verified', icon: <Icon />});
|
|
118
|
+
const iconEl = screen.getByTestId(ICON_TESTID);
|
|
119
|
+
expect(iconEl.closest('[aria-hidden="true"]')).not.toBeNull();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it.each([false, true, null, undefined, ''])(
|
|
123
|
+
'ignores %s and keeps the plain dot (safe for `cond && <Icon />`)',
|
|
124
|
+
value => {
|
|
125
|
+
const dot = renderDot({
|
|
126
|
+
variant: 'error',
|
|
127
|
+
label: 'Offline',
|
|
128
|
+
icon: value,
|
|
129
|
+
});
|
|
130
|
+
expect(dot.childElementCount).toBe(0);
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
it('keeps the accessible name on the dot when an icon renders', () => {
|
|
135
|
+
const dot = renderDot({
|
|
136
|
+
variant: 'success',
|
|
137
|
+
label: 'Verified',
|
|
138
|
+
icon: <Icon />,
|
|
139
|
+
});
|
|
140
|
+
expect(dot).toHaveAttribute('role', 'img');
|
|
141
|
+
expect(dot).toHaveAttribute('aria-label', 'Verified');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('variant ink (a passed icon paints from currentColor)', () => {
|
|
146
|
+
it('pairs the warning plate with the dedicated dark on-warning ink', () => {
|
|
147
|
+
// The regression this guards: a light surface ink on the yellow warning
|
|
148
|
+
// plate lands near 2:1, while `--color-on-warning` is the fixed dark
|
|
149
|
+
// ink (~9.6:1). An icon inherits the ink via `currentColor`, so the
|
|
150
|
+
// pairing is what keeps custom icons legible.
|
|
151
|
+
const probe = stylex.create({
|
|
152
|
+
warning: {
|
|
153
|
+
backgroundColor: colorVars['--color-warning'],
|
|
154
|
+
color: colorVars['--color-on-warning'],
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
const dot = renderDot({variant: 'warning', label: 'Degraded'});
|
|
158
|
+
const atomicClasses = (stylex.props(probe.warning).className ?? '')
|
|
159
|
+
.split(' ')
|
|
160
|
+
// Dev mode prepends a per-file `File__style.key` debug class that
|
|
161
|
+
// legitimately differs between the probe and the component.
|
|
162
|
+
.filter(cls => !cls.includes('__'));
|
|
163
|
+
expect(atomicClasses.length).toBeGreaterThan(0);
|
|
164
|
+
for (const cls of atomicClasses) {
|
|
165
|
+
expect(dot.className).toContain(cls);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('accessible name (label reaches AT without hover)', () => {
|
|
171
|
+
it('exposes the status label as the accessible name for every variant, without a tooltip', () => {
|
|
172
|
+
const variants = [
|
|
173
|
+
'success',
|
|
174
|
+
'warning',
|
|
175
|
+
'error',
|
|
176
|
+
'accent',
|
|
177
|
+
'neutral',
|
|
178
|
+
] as const;
|
|
179
|
+
for (const variant of variants) {
|
|
180
|
+
const {unmount} = render(
|
|
181
|
+
<StatusDot variant={variant} label={`Status: ${variant}`} />,
|
|
182
|
+
);
|
|
183
|
+
const dot = screen.getByRole('img', {name: `Status: ${variant}`});
|
|
184
|
+
expect(dot).toHaveAttribute('aria-label', `Status: ${variant}`);
|
|
185
|
+
// The name must not depend on hover or focus.
|
|
186
|
+
expect(dot.getAttribute('tabindex')).toBeNull();
|
|
187
|
+
unmount();
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
84
191
|
});
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
* - /packages/cli/assets/templates/blocks/components/StatusDot/ (showcase blocks)
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import type {ReactNode} from 'react';
|
|
20
|
+
|
|
19
21
|
import * as stylex from '@stylexjs/stylex';
|
|
20
22
|
import {colorVars} from '../theme/tokens.stylex';
|
|
21
23
|
import type {BaseProps} from '../BaseProps';
|
|
22
24
|
import {Tooltip} from '../Tooltip/Tooltip';
|
|
23
|
-
import {mergeProps} from '../utils';
|
|
25
|
+
import {isRenderable, mergeProps} from '../utils';
|
|
24
26
|
import {themeProps} from '../utils/themeProps';
|
|
25
27
|
import type {StatusDotVariantMap} from './index';
|
|
26
28
|
|
|
@@ -33,16 +35,21 @@ const pulseKeyframes = stylex.keyframes({
|
|
|
33
35
|
'100%': {opacity: 1},
|
|
34
36
|
});
|
|
35
37
|
|
|
38
|
+
/** Fixed dot size in px. A user-supplied icon is drawn into this same field. */
|
|
39
|
+
const DOT_SIZE = 8;
|
|
40
|
+
|
|
36
41
|
/**
|
|
37
42
|
* Base styles
|
|
38
43
|
*/
|
|
39
44
|
const styles = stylex.create({
|
|
40
45
|
base: {
|
|
41
|
-
display: 'inline-
|
|
46
|
+
display: 'inline-flex',
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
justifyContent: 'center',
|
|
42
49
|
borderRadius: '50%',
|
|
43
50
|
flexShrink: 0,
|
|
44
|
-
width:
|
|
45
|
-
height:
|
|
51
|
+
width: `${DOT_SIZE}px`,
|
|
52
|
+
height: `${DOT_SIZE}px`,
|
|
46
53
|
},
|
|
47
54
|
pulsing: {
|
|
48
55
|
animationName: pulseKeyframes,
|
|
@@ -55,26 +62,49 @@ const styles = stylex.create({
|
|
|
55
62
|
animationName: 'none',
|
|
56
63
|
},
|
|
57
64
|
},
|
|
65
|
+
// A user-supplied icon fills the whole 8px field and paints from
|
|
66
|
+
// `currentColor` (the variant's ink).
|
|
67
|
+
icon: {
|
|
68
|
+
display: 'flex',
|
|
69
|
+
alignItems: 'center',
|
|
70
|
+
justifyContent: 'center',
|
|
71
|
+
lineHeight: 0,
|
|
72
|
+
width: `${DOT_SIZE}px`,
|
|
73
|
+
height: `${DOT_SIZE}px`,
|
|
74
|
+
},
|
|
58
75
|
});
|
|
59
76
|
|
|
60
77
|
/**
|
|
61
|
-
* Variant styles mapping to theme color tokens
|
|
78
|
+
* Variant styles mapping to theme color tokens.
|
|
79
|
+
*
|
|
80
|
+
* Each variant sets both the plate colour and an ink colour: a user-supplied
|
|
81
|
+
* `icon` paints from `currentColor`, so plate and ink can never drift out of
|
|
82
|
+
* contrast (same contract as AvatarStatusDot). The ink is each plate's
|
|
83
|
+
* dedicated `--color-on-*` pairing (the Badge precedent), not the surface
|
|
84
|
+
* colour: on-warning is a fixed dark ink, which keeps an icon legible on the
|
|
85
|
+
* yellow plate (~9.6:1) where a light surface ink lands near 2:1. Neutral has
|
|
86
|
+
* no `--color-on-*` token; its mid-grey plate takes the surface ink.
|
|
62
87
|
*/
|
|
63
88
|
const variants = stylex.create({
|
|
64
89
|
success: {
|
|
65
90
|
backgroundColor: colorVars['--color-success'],
|
|
91
|
+
color: colorVars['--color-on-success'],
|
|
66
92
|
},
|
|
67
93
|
warning: {
|
|
68
94
|
backgroundColor: colorVars['--color-warning'],
|
|
95
|
+
color: colorVars['--color-on-warning'],
|
|
69
96
|
},
|
|
70
97
|
error: {
|
|
71
98
|
backgroundColor: colorVars['--color-error'],
|
|
99
|
+
color: colorVars['--color-on-error'],
|
|
72
100
|
},
|
|
73
101
|
accent: {
|
|
74
102
|
backgroundColor: colorVars['--color-accent'],
|
|
103
|
+
color: colorVars['--color-on-accent'],
|
|
75
104
|
},
|
|
76
105
|
neutral: {
|
|
77
106
|
backgroundColor: colorVars['--color-icon-secondary'],
|
|
107
|
+
color: colorVars['--color-background-surface'],
|
|
78
108
|
},
|
|
79
109
|
});
|
|
80
110
|
|
|
@@ -92,7 +122,8 @@ export interface StatusDotProps extends BaseProps<HTMLSpanElement> {
|
|
|
92
122
|
*/
|
|
93
123
|
variant: StatusDotVariant;
|
|
94
124
|
/**
|
|
95
|
-
* Accessible label describing the status. Required for a11y
|
|
125
|
+
* Accessible label describing the status. Required for a11y — it is the
|
|
126
|
+
* dot's `aria-label`, so the status reaches screen readers without hover.
|
|
96
127
|
*/
|
|
97
128
|
label: string;
|
|
98
129
|
/**
|
|
@@ -106,12 +137,36 @@ export interface StatusDotProps extends BaseProps<HTMLSpanElement> {
|
|
|
106
137
|
* When omitted, no tooltip is rendered.
|
|
107
138
|
*/
|
|
108
139
|
tooltip?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Optional icon to render centered inside the dot. Accepts any ReactNode
|
|
142
|
+
* (typically an SVG icon), painted in the dot's `currentColor` ink. Same
|
|
143
|
+
* contract as `AvatarStatusDot`'s `icon`.
|
|
144
|
+
*
|
|
145
|
+
* By default the dot is a colour-only signal; an icon gives the status a
|
|
146
|
+
* non-colour mark, so use a different icon per status — the same icon on
|
|
147
|
+
* every variant leaves the statuses distinguishable by colour alone
|
|
148
|
+
* (WCAG 2.1 SC 1.4.1). Booleans and empty strings are ignored (safe for
|
|
149
|
+
* `cond && <Icon />`).
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```
|
|
153
|
+
* <StatusDot variant="success" label="Verified" icon={<CheckIcon />} />
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
icon?: ReactNode;
|
|
109
157
|
}
|
|
110
158
|
|
|
111
159
|
/**
|
|
112
160
|
* A small colored dot indicator for status display (online/offline, severity, etc).
|
|
113
161
|
*
|
|
114
|
-
* Fixed 8px size.
|
|
162
|
+
* Fixed 8px size. By default the dot conveys status by colour only, which is
|
|
163
|
+
* not accessible in isolation (WCAG 2.1 SC 1.4.1) — treat it as a signal the
|
|
164
|
+
* surrounding UI must make accessible: use it as a binary present/absent
|
|
165
|
+
* signal, pair it with a visible label, pass `icon` so the status carries a
|
|
166
|
+
* non-colour mark, or convey the status accessibly elsewhere. See the usage
|
|
167
|
+
* guidance in the component docs.
|
|
168
|
+
*
|
|
169
|
+
* Renders as a non-focusable `<span>` with `role="img"` and
|
|
115
170
|
* `aria-label` for accessibility. Styles use Astryx theme tokens via StyleX.
|
|
116
171
|
* Wrap your app in `<Theme>` to apply a theme.
|
|
117
172
|
*
|
|
@@ -121,6 +176,7 @@ export interface StatusDotProps extends BaseProps<HTMLSpanElement> {
|
|
|
121
176
|
* <StatusDot variant="error" label="Offline" />
|
|
122
177
|
* <StatusDot variant="success" label="Live" isPulsing />
|
|
123
178
|
* <StatusDot variant="success" label="Online" tooltip="Online" />
|
|
179
|
+
* <StatusDot variant="success" label="Verified" icon={<CheckIcon />} />
|
|
124
180
|
* ```
|
|
125
181
|
*/
|
|
126
182
|
export function StatusDot({
|
|
@@ -128,12 +184,16 @@ export function StatusDot({
|
|
|
128
184
|
label,
|
|
129
185
|
isPulsing = false,
|
|
130
186
|
tooltip,
|
|
187
|
+
icon,
|
|
131
188
|
xstyle,
|
|
132
189
|
className,
|
|
133
190
|
style,
|
|
134
191
|
ref,
|
|
135
192
|
...props
|
|
136
193
|
}: StatusDotProps) {
|
|
194
|
+
// Booleans and empty renders don't count (safe for `cond && <Icon />`) —
|
|
195
|
+
// same contract as AvatarStatusDot.
|
|
196
|
+
const showsIcon = isRenderable(icon);
|
|
137
197
|
const dot = (
|
|
138
198
|
<span
|
|
139
199
|
ref={ref}
|
|
@@ -151,8 +211,13 @@ export function StatusDot({
|
|
|
151
211
|
className,
|
|
152
212
|
style,
|
|
153
213
|
)}
|
|
154
|
-
{...props}
|
|
155
|
-
|
|
214
|
+
{...props}>
|
|
215
|
+
{showsIcon && (
|
|
216
|
+
<span aria-hidden="true" {...stylex.props(styles.icon)}>
|
|
217
|
+
{icon}
|
|
218
|
+
</span>
|
|
219
|
+
)}
|
|
220
|
+
</span>
|
|
156
221
|
);
|
|
157
222
|
|
|
158
223
|
if (tooltip) {
|
package/src/Switch/Switch.tsx
CHANGED
|
@@ -47,6 +47,7 @@ import type {BaseProps} from '../BaseProps';
|
|
|
47
47
|
import type {SizeValue} from '../utils/types';
|
|
48
48
|
import {themeProps} from '../utils/themeProps';
|
|
49
49
|
import {VisuallyHidden} from '../VisuallyHidden';
|
|
50
|
+
import {useResolvedRequired} from '../hooks/useResolvedRequired';
|
|
50
51
|
|
|
51
52
|
const wrapperSizeStyles = stylex.create({
|
|
52
53
|
sm: {
|
|
@@ -503,6 +504,10 @@ export function Switch({
|
|
|
503
504
|
const id = useId();
|
|
504
505
|
const descriptionID = useId();
|
|
505
506
|
const statusMessageID = useId();
|
|
507
|
+
// Announce the effective required state (form default included) while the
|
|
508
|
+
// native `required` stays bound to the explicit `isRequired` so a layout
|
|
509
|
+
// default never switches on browser validation.
|
|
510
|
+
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
|
|
506
511
|
|
|
507
512
|
const [, startTransition] = useTransition();
|
|
508
513
|
const [optimisticValue, setOptimisticValue] = useOptimistic(value);
|
|
@@ -559,6 +564,7 @@ export function Switch({
|
|
|
559
564
|
aria-disabled={showsDisabledMessage ? 'true' : undefined}
|
|
560
565
|
form={showsDisabledMessage ? '' : undefined}
|
|
561
566
|
required={isRequired}
|
|
567
|
+
aria-required={isEffectivelyRequired ? 'true' : undefined}
|
|
562
568
|
onChange={e => {
|
|
563
569
|
if (isDisabled || isBusy) {
|
|
564
570
|
return;
|