@hyphen/hyphen-components 7.9.0 → 8.0.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.
- package/dist/css/fonts.css +1 -1
- package/dist/css/index.css +292 -150
- package/dist/css/reset.css +1 -1
- package/dist/css/utilities.css +480 -38
- package/dist/css/variables.css +170 -25
- package/dist/hyphen-components.cjs.development.js +244 -311
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +2 -2
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +198 -265
- package/dist/hyphen-components.esm.js.map +1 -1
- package/dist/index.d.ts +25 -60
- package/package.json +3 -3
- package/src/components/Alert/Alert.mdx +1 -1
- package/src/components/Alert/Alert.module.scss +29 -34
- package/src/components/Alert/Alert.stories.tsx +11 -3
- package/src/components/Alert/Alert.test.tsx +17 -11
- package/src/components/Alert/Alert.tsx +9 -16
- package/src/components/Badge/Badge.mdx +46 -4
- package/src/components/Badge/Badge.module.scss +235 -185
- package/src/components/Badge/Badge.stories.tsx +126 -36
- package/src/components/Badge/Badge.test.tsx +180 -21
- package/src/components/Badge/Badge.tsx +56 -21
- package/src/components/Drawer/Drawer.mdx +14 -16
- package/src/components/Formik/Formik.stories.tsx +3 -5
- package/src/components/Formik/FormikTimePicker/FormikTimePicker.test.tsx +34 -67
- package/src/components/Formik/FormikTimePicker/FormikTimePicker.tsx +0 -2
- package/src/components/Table/Table.stories.tsx +4 -4
- package/src/components/TimePicker/TimePicker.mdx +3 -11
- package/src/components/TimePicker/TimePicker.stories.tsx +61 -60
- package/src/components/TimePicker/TimePicker.test.tsx +76 -7
- package/src/components/TimePicker/TimePicker.tsx +37 -7
- package/src/components/Tooltip/Tooltip.stories.tsx +1 -1
- package/src/docs/Colors.mdx +13 -0
- package/src/index.ts +0 -2
- package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.test.tsx +0 -175
- package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.tsx +0 -38
- package/src/components/TimePickerNative/TimePickerNative.mdx +0 -67
- package/src/components/TimePickerNative/TimePickerNative.stories.tsx +0 -150
- package/src/components/TimePickerNative/TimePickerNative.test.tsx +0 -117
- package/src/components/TimePickerNative/TimePickerNative.tsx +0 -93
package/dist/index.d.ts
CHANGED
|
@@ -119,6 +119,10 @@ type ValueOrFunction<TValue, TArg> = TValue | ValueFunction<TValue, TArg>;
|
|
|
119
119
|
type AlertVariant = 'info' | 'success' | 'warning' | 'danger' | 'default';
|
|
120
120
|
|
|
121
121
|
interface AlertProps {
|
|
122
|
+
/**
|
|
123
|
+
* The alert's contents.
|
|
124
|
+
*/
|
|
125
|
+
children?: ReactNode;
|
|
122
126
|
/**
|
|
123
127
|
* Custom class to apply to the alert.
|
|
124
128
|
*/
|
|
@@ -131,10 +135,6 @@ interface AlertProps {
|
|
|
131
135
|
* Renders a version of the alert with smaller padding.
|
|
132
136
|
*/
|
|
133
137
|
isCompact?: boolean;
|
|
134
|
-
/**
|
|
135
|
-
* @deprecated Use children instead. The text message or ReactNode to be rendered in the alert.
|
|
136
|
-
*/
|
|
137
|
-
message?: string | ReactNode;
|
|
138
138
|
/**
|
|
139
139
|
* Whether the alert can be closed by the user. If `true` it will render
|
|
140
140
|
* the 'close' icon on the right hand side of the alert.
|
|
@@ -410,18 +410,27 @@ declare const Box: FC<BoxProps>;
|
|
|
410
410
|
declare const boxPropsKeys: (keyof Pick<BoxProps, KnownKeys<BoxProps>>)[];
|
|
411
411
|
|
|
412
412
|
type BadgeSize = 'sm' | 'md' | 'lg';
|
|
413
|
-
type BadgeVariant = '
|
|
414
|
-
|
|
413
|
+
type BadgeVariant = 'solid' | 'soft' | 'surface' | 'outline';
|
|
414
|
+
type BadgeHue = 'grey' | 'blue' | 'green' | 'yellow' | 'red' | 'purple' | 'orange' | 'brand';
|
|
415
|
+
type BadgeSemanticColor = 'danger' | 'success' | 'warning' | 'info';
|
|
416
|
+
type BadgeColor = BadgeHue | BadgeSemanticColor;
|
|
417
|
+
type BadgeRadius = 'none' | 'sm' | 'md' | 'lg' | 'full';
|
|
418
|
+
interface BadgeProps extends Omit<BoxProps, 'color' | 'radius'> {
|
|
419
|
+
/**
|
|
420
|
+
* The color of the badge. Accepts a hue, or one of the semantic names
|
|
421
|
+
* (`danger`, `success`, `warning`, `info`) which map onto `red`, `green`, `yellow` and `blue`.
|
|
422
|
+
*/
|
|
423
|
+
color?: BadgeColor;
|
|
415
424
|
/**
|
|
416
|
-
*
|
|
425
|
+
* The roundness of the badge's corners.
|
|
417
426
|
*/
|
|
418
|
-
|
|
427
|
+
radius?: BadgeRadius;
|
|
419
428
|
/**
|
|
420
429
|
* The size of the badge.
|
|
421
430
|
*/
|
|
422
431
|
size?: BadgeSize | ResponsiveProp<BadgeSize>;
|
|
423
432
|
/**
|
|
424
|
-
* The
|
|
433
|
+
* The visual style of the badge. Use `color` to set its color.
|
|
425
434
|
*/
|
|
426
435
|
variant?: BadgeVariant;
|
|
427
436
|
}
|
|
@@ -1792,51 +1801,7 @@ interface FormikTextareaInputProps extends Omit<TextareaInputProps, 'onChange'>
|
|
|
1792
1801
|
}
|
|
1793
1802
|
declare const FormikTextareaInput: FC<FormikTextareaInputProps>;
|
|
1794
1803
|
|
|
1795
|
-
|
|
1796
|
-
/**
|
|
1797
|
-
* Options to govern the display of the option labels in the select.
|
|
1798
|
-
* This is a direct passthrough to the second argument of JS `toLocaleTimeString`.
|
|
1799
|
-
* [More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
|
|
1800
|
-
*/
|
|
1801
|
-
dateDisplayOptions?: Intl.DateTimeFormatOptions;
|
|
1802
|
-
/**
|
|
1803
|
-
* End hour and minute
|
|
1804
|
-
*/
|
|
1805
|
-
endTime?: {
|
|
1806
|
-
hour: number;
|
|
1807
|
-
minute: number;
|
|
1808
|
-
};
|
|
1809
|
-
/**
|
|
1810
|
-
* Interval of displayed times (in seconds). Defaults to 900 seconds (15 minutes).
|
|
1811
|
-
*/
|
|
1812
|
-
interval?: number;
|
|
1813
|
-
/**
|
|
1814
|
-
* Locale(s) to be passed down in order to format the label values in the select.
|
|
1815
|
-
* This corresponds to the first argument of JS `toLocaleTimeString`.
|
|
1816
|
-
* [More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
|
|
1817
|
-
*/
|
|
1818
|
-
locales?: string | string[];
|
|
1819
|
-
/**
|
|
1820
|
-
* Start hour and minute
|
|
1821
|
-
*/
|
|
1822
|
-
startTime?: {
|
|
1823
|
-
hour: number;
|
|
1824
|
-
minute: number;
|
|
1825
|
-
};
|
|
1826
|
-
};
|
|
1827
|
-
declare const TimePicker: FC<TimePickerProps>;
|
|
1828
|
-
|
|
1829
|
-
interface FormikTimePickerProps extends Omit<TimePickerProps, 'onChange'> {
|
|
1830
|
-
field: FieldAttributes<HTMLSelectElement>;
|
|
1831
|
-
form: {
|
|
1832
|
-
touched: FormikTouched<FormikValues>;
|
|
1833
|
-
errors: FormikErrors<FormikValues>;
|
|
1834
|
-
};
|
|
1835
|
-
onChange?: TimePickerProps['onChange'];
|
|
1836
|
-
}
|
|
1837
|
-
declare const FormikTimePicker: FC<FormikTimePickerProps>;
|
|
1838
|
-
|
|
1839
|
-
interface TimePickerNativeProps extends Omit<SelectInputNativeProps, 'options'> {
|
|
1804
|
+
interface TimePickerProps extends Omit<SelectInputNativeProps, 'options'> {
|
|
1840
1805
|
/**
|
|
1841
1806
|
* Options to govern the display of the option labels in the select.
|
|
1842
1807
|
* This is a direct passthrough to the second argument of JS `toLocaleTimeString`.
|
|
@@ -1872,17 +1837,17 @@ interface TimePickerNativeProps extends Omit<SelectInputNativeProps, 'options'>
|
|
|
1872
1837
|
*/
|
|
1873
1838
|
value: SelectInputNativeProps['value'];
|
|
1874
1839
|
}
|
|
1875
|
-
declare const
|
|
1840
|
+
declare const TimePicker: FC<TimePickerProps>;
|
|
1876
1841
|
|
|
1877
|
-
interface
|
|
1878
|
-
field: FieldAttributes<
|
|
1842
|
+
interface FormikTimePickerProps extends Omit<TimePickerProps, 'onChange'> {
|
|
1843
|
+
field: FieldAttributes<HTMLSelectElement>;
|
|
1879
1844
|
form: {
|
|
1880
1845
|
touched: FormikTouched<FormikValues>;
|
|
1881
1846
|
errors: FormikErrors<FormikValues>;
|
|
1882
1847
|
};
|
|
1883
|
-
onChange
|
|
1848
|
+
onChange?: TimePickerProps['onChange'];
|
|
1884
1849
|
}
|
|
1885
|
-
declare const
|
|
1850
|
+
declare const FormikTimePicker: FC<FormikTimePickerProps>;
|
|
1886
1851
|
|
|
1887
1852
|
interface FormikSwitchProps {
|
|
1888
1853
|
field: FieldAttributes<HTMLTextAreaElement>;
|
|
@@ -2837,4 +2802,4 @@ declare const Z_INDEX_OPTIONS: ZIndexSize[];
|
|
|
2837
2802
|
declare const Z_INDEX_VALUES: any;
|
|
2838
2803
|
declare const BOX_SHADOW_OPTIONS: BoxShadowSize[];
|
|
2839
2804
|
|
|
2840
|
-
export { Alert, type AlertProps, AspectRatio, BACKGROUND_COLOR_OPTIONS, BASE_COLOR_NAMES, BASE_COLOR_OPTIONS, BORDER_COLOR_OPTIONS, BORDER_RADIUS_OPTIONS, BORDER_SIZE_OPTIONS, BOX_SHADOW_OPTIONS, BREAKPOINTS, BREAKPOINT_OPTIONS, Badge, type BadgeProps, type BadgeSize, type BadgeVariant, type BaseButtonProps, type BaseSpacing, type BorderRadiusSize, Box, type BoxProps, type Breakpoint, type BreakpointSizeWithBase, type BreakpointState, Button, type ButtonProps, type ButtonSize, type ButtonVariant, Calendar, type CalendarProps, Card, CardBaseComponent, type CardProps, type CardStatic, type CardWithStaticComponents, type Cell, Checkbox, CheckboxInput, type CheckboxInputProps, type CheckboxProps, type CheckboxSize, Collapsible, CollapsibleContent, CollapsibleTrigger, type Column, type CssAlignContentValue, type CssAlignItemsValue, type CssDimensionAbbreviation, type CssDimensionUnit, type CssDimensionValue, type CssDisplayValue, type CssFlexDirectionValue, type CssFlexValue, type CssJustifyContentValue, type CssOverflowValue, type CssSpacingAbbreviation, type CssTextAlignValue, type CssWhiteSpaceValue, type CssWordBreakValue, Details, DetailsBaseComponent, type DetailsProps, type DetailsStatic, DetailsSummary, type DetailsSummaryProps, type DetailsWithStaticComponents, type DimensionSize, Drawer, DrawerCloseButton, DrawerContent, DrawerHeader, type DrawerPlacementType, type DrawerProps, DrawerProvider, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, type EventWithColumnKey, type ExtendedToastOptions, FONT_COLOR_OPTIONS, FONT_FAMILY_OPTIONS, FONT_SIZE_OPTIONS, FONT_WEIGHT_OPTIONS, type FilterFunction, type FlexProperty, FormControl, type FormControlProps, FormLabel, type FormLabelProps, FormikCheckboxInput, type FormikCheckboxInputProps, FormikRadioGroup, type FormikRadioGroupProps, FormikSelectInput, FormikSelectInputInset, type FormikSelectInputInsetProps, FormikSelectInputNative, type FormikSelectInputNativeProps, type FormikSelectInputProps, FormikSwitch, type FormikSwitchProps, FormikTextInput, FormikTextInputInset, type FormikTextInputInsetProps, type FormikTextInputProps, FormikTextareaInput, FormikTextareaInputInset, type FormikTextareaInputInsetProps, type FormikTextareaInputProps, FormikTimePicker,
|
|
2805
|
+
export { Alert, type AlertProps, AspectRatio, BACKGROUND_COLOR_OPTIONS, BASE_COLOR_NAMES, BASE_COLOR_OPTIONS, BORDER_COLOR_OPTIONS, BORDER_RADIUS_OPTIONS, BORDER_SIZE_OPTIONS, BOX_SHADOW_OPTIONS, BREAKPOINTS, BREAKPOINT_OPTIONS, Badge, type BadgeColor, type BadgeHue, type BadgeProps, type BadgeRadius, type BadgeSemanticColor, type BadgeSize, type BadgeVariant, type BaseButtonProps, type BaseSpacing, type BorderRadiusSize, Box, type BoxProps, type Breakpoint, type BreakpointSizeWithBase, type BreakpointState, Button, type ButtonProps, type ButtonSize, type ButtonVariant, Calendar, type CalendarProps, Card, CardBaseComponent, type CardProps, type CardStatic, type CardWithStaticComponents, type Cell, Checkbox, CheckboxInput, type CheckboxInputProps, type CheckboxProps, type CheckboxSize, Collapsible, CollapsibleContent, CollapsibleTrigger, type Column, type CssAlignContentValue, type CssAlignItemsValue, type CssDimensionAbbreviation, type CssDimensionUnit, type CssDimensionValue, type CssDisplayValue, type CssFlexDirectionValue, type CssFlexValue, type CssJustifyContentValue, type CssOverflowValue, type CssSpacingAbbreviation, type CssTextAlignValue, type CssWhiteSpaceValue, type CssWordBreakValue, Details, DetailsBaseComponent, type DetailsProps, type DetailsStatic, DetailsSummary, type DetailsSummaryProps, type DetailsWithStaticComponents, type DimensionSize, Drawer, DrawerCloseButton, DrawerContent, DrawerHeader, type DrawerPlacementType, type DrawerProps, DrawerProvider, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, type EventWithColumnKey, type ExtendedToastOptions, FONT_COLOR_OPTIONS, FONT_FAMILY_OPTIONS, FONT_SIZE_OPTIONS, FONT_WEIGHT_OPTIONS, type FilterFunction, type FlexProperty, FormControl, type FormControlProps, FormLabel, type FormLabelProps, FormikCheckboxInput, type FormikCheckboxInputProps, FormikRadioGroup, type FormikRadioGroupProps, FormikSelectInput, FormikSelectInputInset, type FormikSelectInputInsetProps, FormikSelectInputNative, type FormikSelectInputNativeProps, type FormikSelectInputProps, FormikSwitch, type FormikSwitchProps, FormikTextInput, FormikTextInputInset, type FormikTextInputInsetProps, type FormikTextInputProps, FormikTextareaInput, FormikTextareaInputInset, type FormikTextareaInputInsetProps, type FormikTextareaInputProps, FormikTimePicker, type FormikTimePickerProps, FormikToggleGroup, FormikToggleGroupMulti, type FormikToggleGroupMultiProps, type FormikToggleGroupProps, HEADING_SIZE_OPTIONS, HEIGHT_OPTIONS, Heading, type HeadingProps, type HookWindowSize, type HoverableBoxProperties, ICON_NAMES, Icon, type IconProps, type InputRangeProps, LINE_HEIGHT_OPTIONS, Modal, ModalBaseComponent, type ModalProps, type ModalStatic, type ModalWithStaticComponents, Pagination, type PaginationProps, Popover, PopoverAnchor, PopoverContent, PopoverPortal, PopoverTrigger, RadioGroup, type RadioGroupProps, RangeInput, ResponsiveContext, type ResponsiveContextShape, type ResponsiveProp, ResponsiveProvider, type ResponsiveProviderProps, type Row, SPACING_OPTIONS, SelectInput, SelectInputInset, type SelectInputInsetProps, type SelectInputInsetSize, SelectInputNative, type SelectInputNativeOption, type SelectInputNativeProps, type SelectInputNativeSize, type SelectInputOptions, type SelectInputProps, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarTrigger, type SimulatedEventPayloadType, Spinner, type SpinnerProps, type StylesAndClasses, Switch, type SwitchProps, type SwitchSize, Table, type TableProps, TextInput, TextInputInset, type TextInputInsetProps, type TextInputInsetSize, type TextInputProps, type TextInputSize, type TextInputSizeType, TextareaInput, TextareaInputInset, type TextareaInputInsetProps, type TextareaInputInsetSize, type TextareaInputProps, type TextareaInputSize, type Theme, ThemeProvider, ThemeProviderContext, TimePicker, type TimePickerProps, type Toast, ToastContainer, type ToastContainerProps, type ToastOptions, type ToastPosition, type ToastType, Toggle, ToggleGroup, ToggleGroupItem, type ToggleVariant$1 as ToggleVariant, Tooltip, TooltipContent, TooltipPortal, TooltipProvider, TooltipTrigger, type UnknownPropertiesObjType, type UseOpenCloseProps, type UseOpenCloseState, type ValueFunction, type ValueOrFunction, WIDTH_OPTIONS, Z_INDEX_OPTIONS, Z_INDEX_VALUES, boxPropsKeys, createRectRef, cssShorthandToClasses, doesStringIncludeCssUnit, filter, generateBaseClasses, generateResponsiveClasses, getAutoCompleteValue, getColumnKeys, getDimensionClasses, getDimensionCss, getDimensionStyles, getElementType, getFlexClasses, getFlexCss, getFlexStyles, handleReactRouterClick, isFunction, isModifiedEvent, isValidSpacingValue, mergeRefs, parsePropertyValue, prefersReducedMotion, resolveValue, toast, useBreakpoint, useDrawer, useIsMobile, useIsomorphicLayoutEffect, useOpenClose, useSidebar, useTheme, useToasts, useWindowSize };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyphen/hyphen-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "@hyphen"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"react-select": "^5.10.0",
|
|
57
57
|
"react-select-event": "^5.5.1",
|
|
58
58
|
"uuid": "^11.1.1",
|
|
59
|
-
"@hyphen/hyphen-design-tokens": "^
|
|
59
|
+
"@hyphen/hyphen-design-tokens": "^8.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@babel/core": "^7.27.4",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"jest-preview": "^0.3.1",
|
|
103
103
|
"mini-css-extract-plugin": "^2.9.1",
|
|
104
104
|
"playwright": "^1.60.0",
|
|
105
|
-
"postcss": "^8.
|
|
105
|
+
"postcss": "^8.5.18",
|
|
106
106
|
"postcss-loader": "^7.3.4",
|
|
107
107
|
"postcss-modules": "^6.0.0",
|
|
108
108
|
"react": "^18.3.1",
|
|
@@ -16,7 +16,7 @@ Use alerts to display feedback for users about specific actions, or states of an
|
|
|
16
16
|
|
|
17
17
|
## Variants
|
|
18
18
|
|
|
19
|
-
Alerts come in different variants based on the kind of feedback being delivered to the user. Additionally, a combination of icon, title, and
|
|
19
|
+
Alerts come in different variants based on the kind of feedback being delivered to the user. Additionally, a combination of icon, title, and content can be used depending on your content needs.
|
|
20
20
|
|
|
21
21
|
<Canvas of={Stories.Variants} />
|
|
22
22
|
|
|
@@ -1,20 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Each variant class declares the three semantic values the base `.alert` block consumes.
|
|
3
|
+
* The values mirror the Badge `surface` variant, so an Alert and a surface Badge of the
|
|
4
|
+
* same semantic colour read as the same tint in both light and dark mode.
|
|
5
|
+
*/
|
|
6
|
+
@mixin alert-variant($variant) {
|
|
7
|
+
--alert-background: var(--color-background-alert-#{$variant});
|
|
8
|
+
--alert-border: var(--color-border-alert-#{$variant});
|
|
9
|
+
--alert-font: var(--color-font-alert-#{$variant});
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
.alert {
|
|
2
13
|
border-width: var(--size-border-width-sm);
|
|
3
14
|
border-style: solid;
|
|
4
15
|
box-shadow: var(--size-box-shadow-0);
|
|
5
16
|
font-family: var(--assets-font-family-body);
|
|
17
|
+
background: var(--alert-background);
|
|
18
|
+
border-color: var(--alert-border);
|
|
19
|
+
color: var(--alert-font);
|
|
6
20
|
|
|
21
|
+
/* Icon and close button share the variant font colour so the whole alert reads as one tint. */
|
|
7
22
|
.close-icon {
|
|
8
23
|
> button {
|
|
9
24
|
border: 0;
|
|
10
25
|
background: none;
|
|
11
26
|
cursor: pointer;
|
|
12
27
|
padding: 0;
|
|
13
|
-
color:
|
|
28
|
+
color: inherit;
|
|
14
29
|
font: inherit;
|
|
15
30
|
|
|
16
31
|
&:hover {
|
|
17
|
-
color:
|
|
32
|
+
color: inherit;
|
|
18
33
|
}
|
|
19
34
|
}
|
|
20
35
|
}
|
|
@@ -25,50 +40,30 @@
|
|
|
25
40
|
}
|
|
26
41
|
|
|
27
42
|
.alert__default {
|
|
28
|
-
|
|
29
|
-
background: var(--color-base-grey-100);
|
|
30
|
-
border-color: var(--color-base-grey-200);
|
|
43
|
+
@include alert-variant('default');
|
|
31
44
|
}
|
|
32
45
|
|
|
33
46
|
.alert__info {
|
|
34
|
-
|
|
35
|
-
background: var(--color-base-blue-50);
|
|
36
|
-
border-color: var(--color-base-blue-200);
|
|
47
|
+
@include alert-variant('info');
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
.alert__success {
|
|
40
|
-
|
|
41
|
-
background: var(--color-base-green-50);
|
|
42
|
-
border-color: var(--color-base-green-200);
|
|
51
|
+
@include alert-variant('success');
|
|
43
52
|
}
|
|
44
53
|
|
|
54
|
+
/*
|
|
55
|
+
* `--alert-warning-background-color` stays supported as a consumer-facing override so
|
|
56
|
+
* existing usages that recolour only the warning background keep working.
|
|
57
|
+
*/
|
|
45
58
|
.alert__warning {
|
|
46
|
-
|
|
47
|
-
background: var(
|
|
59
|
+
--alert-background: var(
|
|
48
60
|
--alert-warning-background-color,
|
|
49
|
-
var(--color-
|
|
61
|
+
var(--color-background-alert-warning)
|
|
50
62
|
);
|
|
51
|
-
border
|
|
63
|
+
--alert-border: var(--color-border-alert-warning);
|
|
64
|
+
--alert-font: var(--color-font-alert-warning);
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
.alert__danger {
|
|
55
|
-
|
|
56
|
-
background: var(--color-base-red-50);
|
|
57
|
-
border-color: var(--color-base-red-200);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.alert__icon__default {
|
|
61
|
-
color: var(--color-base-grey-600);
|
|
62
|
-
}
|
|
63
|
-
.alert__icon__info {
|
|
64
|
-
color: var(--color-base-blue-500);
|
|
65
|
-
}
|
|
66
|
-
.alert__icon__success {
|
|
67
|
-
color: var(--color-base-green-500);
|
|
68
|
-
}
|
|
69
|
-
.alert__icon__warning {
|
|
70
|
-
color: var(--color-base-yellow-500);
|
|
71
|
-
}
|
|
72
|
-
.alert__icon__danger {
|
|
73
|
-
color: var(--color-base-red-500);
|
|
68
|
+
@include alert-variant('danger');
|
|
74
69
|
}
|
|
@@ -2,6 +2,7 @@ import { Alert } from './Alert';
|
|
|
2
2
|
import { AlertVariant } from './Alert.types';
|
|
3
3
|
import { Button } from '../Button/Button';
|
|
4
4
|
import { ALERT_VARIANTS } from './Alert.constants';
|
|
5
|
+
import { allModes } from '../../modes';
|
|
5
6
|
|
|
6
7
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
7
8
|
import React from 'react';
|
|
@@ -20,10 +21,9 @@ const meta: Meta<typeof Alert> = {
|
|
|
20
21
|
control: 'text',
|
|
21
22
|
description: 'The title for the alert',
|
|
22
23
|
},
|
|
23
|
-
|
|
24
|
+
children: {
|
|
24
25
|
control: 'text',
|
|
25
|
-
description:
|
|
26
|
-
'The text message to be rendered in the alert (deprecated, use children instead)',
|
|
26
|
+
description: 'The content to be rendered in the alert',
|
|
27
27
|
},
|
|
28
28
|
hasIcon: {
|
|
29
29
|
control: 'boolean',
|
|
@@ -48,6 +48,14 @@ const meta: Meta<typeof Alert> = {
|
|
|
48
48
|
hasIcon: false,
|
|
49
49
|
isCompact: false,
|
|
50
50
|
},
|
|
51
|
+
parameters: {
|
|
52
|
+
chromatic: {
|
|
53
|
+
modes: {
|
|
54
|
+
light: allModes['light'],
|
|
55
|
+
dark: allModes['dark'],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
51
59
|
};
|
|
52
60
|
|
|
53
61
|
export default meta;
|
|
@@ -7,7 +7,7 @@ describe('Alert', () => {
|
|
|
7
7
|
describe('Default', () => {
|
|
8
8
|
test('It renders an alert with a simple text message', () => {
|
|
9
9
|
const message = 'Hello world!';
|
|
10
|
-
render(<Alert
|
|
10
|
+
render(<Alert>{message}</Alert>);
|
|
11
11
|
|
|
12
12
|
const alert = screen.getByRole('alert');
|
|
13
13
|
expect(alert).toBeInTheDocument();
|
|
@@ -20,7 +20,9 @@ describe('Alert', () => {
|
|
|
20
20
|
ALERT_VARIANTS.map((variant, index) =>
|
|
21
21
|
test(`renders variant background color ${ALERT_VARIANTS[index]}`, () => {
|
|
22
22
|
const { getByRole } = render(
|
|
23
|
-
<Alert variant={variant}
|
|
23
|
+
<Alert variant={variant} key={variant}>
|
|
24
|
+
{variant}
|
|
25
|
+
</Alert>
|
|
24
26
|
);
|
|
25
27
|
expect(getByRole('alert').classList).toContain(`alert__${variant}`);
|
|
26
28
|
})
|
|
@@ -30,7 +32,7 @@ describe('Alert', () => {
|
|
|
30
32
|
describe('Custom Class', () => {
|
|
31
33
|
test('It renders with a custom class if provided', () => {
|
|
32
34
|
const message = 'Hello world!';
|
|
33
|
-
render(<Alert
|
|
35
|
+
render(<Alert className="custom-class">{message}</Alert>);
|
|
34
36
|
|
|
35
37
|
const alert = screen.getByRole('alert');
|
|
36
38
|
expect(alert).toHaveClass('custom-class');
|
|
@@ -47,10 +49,14 @@ describe('Alert', () => {
|
|
|
47
49
|
'danger' as const,
|
|
48
50
|
];
|
|
49
51
|
|
|
50
|
-
const { rerender } = render(<Alert
|
|
52
|
+
const { rerender } = render(<Alert>{message}</Alert>);
|
|
51
53
|
|
|
52
54
|
variants.forEach((variant) => {
|
|
53
|
-
rerender(
|
|
55
|
+
rerender(
|
|
56
|
+
<Alert variant={variant} hasIcon>
|
|
57
|
+
{message}
|
|
58
|
+
</Alert>
|
|
59
|
+
);
|
|
54
60
|
const alertIcon = screen.getByTestId(`alert-icon-${variant}-test-id`);
|
|
55
61
|
expect(alertIcon).toBeInTheDocument();
|
|
56
62
|
});
|
|
@@ -61,7 +67,7 @@ describe('Alert', () => {
|
|
|
61
67
|
test('It renders an alert with a title if passed', () => {
|
|
62
68
|
const message = 'Hello world!';
|
|
63
69
|
const title = 'title';
|
|
64
|
-
render(<Alert title={title}
|
|
70
|
+
render(<Alert title={title}>{message}</Alert>);
|
|
65
71
|
|
|
66
72
|
const alert = screen.getByRole('alert');
|
|
67
73
|
expect(alert).toBeInTheDocument();
|
|
@@ -71,12 +77,12 @@ describe('Alert', () => {
|
|
|
71
77
|
});
|
|
72
78
|
|
|
73
79
|
describe('With Custom JSX', () => {
|
|
74
|
-
test('It renders custom JSX if passed
|
|
80
|
+
test('It renders custom JSX if passed as children', () => {
|
|
75
81
|
const jsxMessage: ReactNode = (
|
|
76
82
|
<button type="button">I am a button!</button>
|
|
77
83
|
);
|
|
78
84
|
|
|
79
|
-
render(<Alert
|
|
85
|
+
render(<Alert>{jsxMessage}</Alert>);
|
|
80
86
|
|
|
81
87
|
const alertButton = screen.getByRole('button');
|
|
82
88
|
expect(alertButton).toBeInTheDocument();
|
|
@@ -95,13 +101,13 @@ describe('Alert', () => {
|
|
|
95
101
|
expect(alertButton.textContent).toBe('I am a button!');
|
|
96
102
|
});
|
|
97
103
|
|
|
98
|
-
test('Render prop supersedes
|
|
104
|
+
test('Render prop supersedes children', () => {
|
|
99
105
|
const jsxRenderProp = (): ReactNode => (
|
|
100
106
|
<button type="button">I am a button!</button>
|
|
101
107
|
);
|
|
102
108
|
const message = 'Hello world!';
|
|
103
109
|
|
|
104
|
-
render(<Alert render={jsxRenderProp}
|
|
110
|
+
render(<Alert render={jsxRenderProp}>{message}</Alert>);
|
|
105
111
|
|
|
106
112
|
const alertButton = screen.getByRole('button');
|
|
107
113
|
expect(alertButton).toBeInTheDocument();
|
|
@@ -114,7 +120,7 @@ describe('Alert', () => {
|
|
|
114
120
|
describe('Compact', () => {
|
|
115
121
|
test('It renders with the compact class when isCompact prop is true', () => {
|
|
116
122
|
const message = 'Hello world!';
|
|
117
|
-
render(<Alert
|
|
123
|
+
render(<Alert isCompact>{message}</Alert>);
|
|
118
124
|
|
|
119
125
|
const alert = screen.getByRole('alert');
|
|
120
126
|
expect(alert).toHaveClass('p-md');
|
|
@@ -15,6 +15,10 @@ import { AlertVariant } from './Alert.types';
|
|
|
15
15
|
import { ALERT_ICONS_MAP } from './Alert.constants';
|
|
16
16
|
|
|
17
17
|
export interface AlertProps {
|
|
18
|
+
/**
|
|
19
|
+
* The alert's contents.
|
|
20
|
+
*/
|
|
21
|
+
children?: ReactNode;
|
|
18
22
|
/**
|
|
19
23
|
* Custom class to apply to the alert.
|
|
20
24
|
*/
|
|
@@ -27,10 +31,6 @@ export interface AlertProps {
|
|
|
27
31
|
* Renders a version of the alert with smaller padding.
|
|
28
32
|
*/
|
|
29
33
|
isCompact?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated Use children instead. The text message or ReactNode to be rendered in the alert.
|
|
32
|
-
*/
|
|
33
|
-
message?: string | ReactNode;
|
|
34
34
|
/**
|
|
35
35
|
* Whether the alert can be closed by the user. If `true` it will render
|
|
36
36
|
* the 'close' icon on the right hand side of the alert.
|
|
@@ -61,7 +61,6 @@ const AlertComponent: FC<AlertProps> = ({
|
|
|
61
61
|
className = '',
|
|
62
62
|
hasIcon = false,
|
|
63
63
|
isCompact = false,
|
|
64
|
-
message = '',
|
|
65
64
|
onClose = undefined,
|
|
66
65
|
render = undefined,
|
|
67
66
|
title = '',
|
|
@@ -95,7 +94,7 @@ const AlertComponent: FC<AlertProps> = ({
|
|
|
95
94
|
if (!hasIcon) return null;
|
|
96
95
|
|
|
97
96
|
return (
|
|
98
|
-
<Box fontSize="md"
|
|
97
|
+
<Box fontSize="md">
|
|
99
98
|
<Icon
|
|
100
99
|
name={ALERT_ICONS_MAP[variant].icon}
|
|
101
100
|
data-testid={`alert-icon-${variant}-test-id`}
|
|
@@ -108,11 +107,7 @@ const AlertComponent: FC<AlertProps> = ({
|
|
|
108
107
|
if (!onClose) return null;
|
|
109
108
|
|
|
110
109
|
return (
|
|
111
|
-
<Box
|
|
112
|
-
margin="0 0 0 auto"
|
|
113
|
-
color="secondary"
|
|
114
|
-
className={styles['close-icon']}
|
|
115
|
-
>
|
|
110
|
+
<Box margin="0 0 0 auto" className={styles['close-icon']}>
|
|
116
111
|
<button
|
|
117
112
|
type="button"
|
|
118
113
|
onClick={handleClose}
|
|
@@ -131,7 +126,7 @@ const AlertComponent: FC<AlertProps> = ({
|
|
|
131
126
|
}
|
|
132
127
|
|
|
133
128
|
return (
|
|
134
|
-
<Box display="block" childGap={
|
|
129
|
+
<Box display="block" childGap={children && title ? '2xs' : undefined}>
|
|
135
130
|
{title && (
|
|
136
131
|
<Box
|
|
137
132
|
as="h4"
|
|
@@ -142,12 +137,10 @@ const AlertComponent: FC<AlertProps> = ({
|
|
|
142
137
|
{title}
|
|
143
138
|
</Box>
|
|
144
139
|
)}
|
|
145
|
-
{children
|
|
146
|
-
(message &&
|
|
147
|
-
(typeof message === 'string' ? <p>{message}</p> : message))}
|
|
140
|
+
{children}
|
|
148
141
|
</Box>
|
|
149
142
|
);
|
|
150
|
-
}, [render,
|
|
143
|
+
}, [render, title, children]);
|
|
151
144
|
|
|
152
145
|
return (
|
|
153
146
|
<Box
|
|
@@ -16,14 +16,56 @@ Badges are used to display the status of an object or of an action that’s been
|
|
|
16
16
|
|
|
17
17
|
## Variants
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
If the `variant` prop is omitted, the badge uses the theme-aware `default` variant.
|
|
19
|
+
The `variant` prop sets the badge's visual style, independent of its color. `soft` is the default.
|
|
21
20
|
|
|
22
21
|
<Canvas of={Stories.Variants} />
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
## Colors
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
The `color` prop sets the badge's color, independent of its variant. Every color is theme-aware and has its own
|
|
26
|
+
dark mode values. `grey` is the default.
|
|
27
|
+
|
|
28
|
+
<Canvas of={Stories.Colors} />
|
|
29
|
+
|
|
30
|
+
`color` also accepts the semantic names `danger`, `success`, `warning` and `info`, which map onto the `red`,
|
|
31
|
+
`green`, `yellow` and `blue` hues. Prefer these when the badge communicates a state rather than a color, so the
|
|
32
|
+
meaning survives a future retheme.
|
|
33
|
+
|
|
34
|
+
<Canvas of={Stories.SemanticColors} />
|
|
35
|
+
|
|
36
|
+
The `brand` color renders the Hyphen gradient when paired with `variant="solid"`. Its other variants are tinted
|
|
37
|
+
with the brand orange, so `brand` and `orange` look the same for `soft`, `surface` and `outline` — `solid` is what
|
|
38
|
+
distinguishes them.
|
|
39
|
+
|
|
40
|
+
## Radius
|
|
41
|
+
|
|
42
|
+
Set `radius` to `none`, `sm`, `md`, `lg`, or `full`. `full` is the default, giving the badge a pill shape.
|
|
43
|
+
|
|
44
|
+
<Canvas of={Stories.Radii} />
|
|
45
|
+
|
|
46
|
+
## With icons
|
|
47
|
+
|
|
48
|
+
Nest an `Icon`, a `Spinner`, or any other graphic alongside the badge's text. Its position in the markup is its
|
|
49
|
+
position in the badge — put it before the text for a leading icon, after for a trailing one. No extra props are
|
|
50
|
+
needed.
|
|
51
|
+
|
|
52
|
+
```jsx
|
|
53
|
+
<Badge variant="solid" color="green">
|
|
54
|
+
<Icon name="check" />
|
|
55
|
+
Verified
|
|
56
|
+
</Badge>
|
|
57
|
+
|
|
58
|
+
<Badge variant="outline" color="yellow">
|
|
59
|
+
Favorite
|
|
60
|
+
<Icon name="star" />
|
|
61
|
+
</Badge>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Nested graphics are scaled to the badge's text size and inherit its text color, so they stay in proportion at
|
|
65
|
+
every `size` and in both themes. The badge also tightens its padding on whichever side carries a graphic rather
|
|
66
|
+
than text, and a badge containing only an icon is padded evenly.
|
|
67
|
+
|
|
68
|
+
<Canvas of={Stories.WithIcons} />
|
|
27
69
|
|
|
28
70
|
## Sizes
|
|
29
71
|
|