@commercetools/nimbus 0.0.1 → 0.0.3
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/index.d.ts +1412 -0
- package/dist/index.js +11183 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +27 -0
- package/dist/index.umd.cjs.map +1 -0
- package/package.json +33 -6
- package/.storybook/apca-check/index.ts +0 -150
- package/.storybook/main.ts +0 -64
- package/.storybook/preview.tsx +0 -92
- package/.storybook/vitest.setup.ts +0 -13
- package/docs/architecture-decisions/adr-0001-consumer-component-apis.md +0 -177
- package/docs/architecture-decisions/adr-0002-compound-component-extraction.md +0 -82
- package/src/components/accordion/accordion-context.tsx +0 -17
- package/src/components/accordion/accordion.mdx +0 -172
- package/src/components/accordion/accordion.recipe.tsx +0 -98
- package/src/components/accordion/accordion.slots.tsx +0 -39
- package/src/components/accordion/accordion.stories.tsx +0 -188
- package/src/components/accordion/accordion.tsx +0 -16
- package/src/components/accordion/accordion.types.tsx +0 -54
- package/src/components/accordion/components/accordion-content.tsx +0 -28
- package/src/components/accordion/components/accordion-group.tsx +0 -27
- package/src/components/accordion/components/accordion-header.tsx +0 -63
- package/src/components/accordion/components/accordion-item.tsx +0 -87
- package/src/components/accordion/index.ts +0 -2
- package/src/components/alert/alert.mdx +0 -92
- package/src/components/alert/alert.recipe.tsx +0 -65
- package/src/components/alert/alert.slots.tsx +0 -46
- package/src/components/alert/alert.stories.tsx +0 -308
- package/src/components/alert/alert.tsx +0 -18
- package/src/components/alert/alert.types.tsx +0 -70
- package/src/components/alert/components/alert.actions.tsx +0 -27
- package/src/components/alert/components/alert.description.tsx +0 -27
- package/src/components/alert/components/alert.dismiss-button.tsx +0 -41
- package/src/components/alert/components/alert.root.tsx +0 -92
- package/src/components/alert/components/alert.title.tsx +0 -29
- package/src/components/alert/index.ts +0 -2
- package/src/components/avatar/avatar.mdx +0 -80
- package/src/components/avatar/avatar.recipe.tsx +0 -36
- package/src/components/avatar/avatar.slots.tsx +0 -16
- package/src/components/avatar/avatar.stories.tsx +0 -136
- package/src/components/avatar/avatar.tsx +0 -34
- package/src/components/avatar/avatar.types.ts +0 -33
- package/src/components/avatar/index.ts +0 -2
- package/src/components/badge/badge.mdx +0 -91
- package/src/components/badge/badge.recipe.tsx +0 -72
- package/src/components/badge/badge.slots.tsx +0 -8
- package/src/components/badge/badge.stories.tsx +0 -124
- package/src/components/badge/badge.tsx +0 -35
- package/src/components/badge/badge.types.tsx +0 -40
- package/src/components/badge/index.ts +0 -2
- package/src/components/bleed/bleed.tsx +0 -1
- package/src/components/bleed/index.ts +0 -1
- package/src/components/box/box.mdx +0 -115
- package/src/components/box/box.stories.tsx +0 -71
- package/src/components/box/box.tsx +0 -11
- package/src/components/box/index.ts +0 -1
- package/src/components/button/button.mdx +0 -169
- package/src/components/button/button.recipe.ts +0 -185
- package/src/components/button/button.slots.tsx +0 -45
- package/src/components/button/button.stories.tsx +0 -369
- package/src/components/button/button.tsx +0 -37
- package/src/components/button/button.types.ts +0 -14
- package/src/components/button/index.ts +0 -2
- package/src/components/card/card.mdx +0 -92
- package/src/components/card/card.recipe.tsx +0 -71
- package/src/components/card/card.slots.tsx +0 -50
- package/src/components/card/card.stories.tsx +0 -175
- package/src/components/card/card.tsx +0 -9
- package/src/components/card/card.types.ts +0 -22
- package/src/components/card/components/card.content.tsx +0 -29
- package/src/components/card/components/card.header.tsx +0 -28
- package/src/components/card/components/card.root.tsx +0 -62
- package/src/components/card/index.ts +0 -2
- package/src/components/checkbox/checkbox.mdx +0 -78
- package/src/components/checkbox/checkbox.recipe.tsx +0 -116
- package/src/components/checkbox/checkbox.slots.tsx +0 -33
- package/src/components/checkbox/checkbox.stories.tsx +0 -200
- package/src/components/checkbox/checkbox.tsx +0 -77
- package/src/components/checkbox/checkbox.types.tsx +0 -22
- package/src/components/checkbox/index.ts +0 -2
- package/src/components/code/code.mdx +0 -17
- package/src/components/code/code.recipe.ts +0 -63
- package/src/components/code/code.tsx +0 -1
- package/src/components/code/index.ts +0 -1
- package/src/components/dialog/dialog.mdx +0 -20
- package/src/components/dialog/dialog.recipe.ts +0 -254
- package/src/components/dialog/dialog.tsx +0 -61
- package/src/components/dialog/index.ts +0 -1
- package/src/components/em/em.mdx +0 -17
- package/src/components/em/em.tsx +0 -1
- package/src/components/em/index.ts +0 -1
- package/src/components/flex/flex.mdx +0 -41
- package/src/components/flex/flex.tsx +0 -1
- package/src/components/flex/index.ts +0 -1
- package/src/components/grid/grid.mdx +0 -156
- package/src/components/grid/grid.stories.tsx +0 -151
- package/src/components/grid/grid.tsx +0 -29
- package/src/components/grid/index.ts +0 -1
- package/src/components/heading/heading.mdx +0 -23
- package/src/components/heading/heading.recipe.ts +0 -49
- package/src/components/heading/heading.tsx +0 -1
- package/src/components/heading/index.ts +0 -1
- package/src/components/highlight/highlight.mdx +0 -18
- package/src/components/highlight/highlight.tsx +0 -1
- package/src/components/highlight/index.ts +0 -1
- package/src/components/icon-button/icon-button.mdx +0 -98
- package/src/components/icon-button/icon-button.stories.tsx +0 -188
- package/src/components/icon-button/icon-button.tsx +0 -21
- package/src/components/icon-button/icon-button.types.tsx +0 -10
- package/src/components/icon-button/index.ts +0 -2
- package/src/components/index.ts +0 -33
- package/src/components/input/index.ts +0 -1
- package/src/components/input/input.mdx +0 -20
- package/src/components/input/input.recipe.ts +0 -95
- package/src/components/input/input.tsx +0 -1
- package/src/components/input-group/index.ts +0 -1
- package/src/components/input-group/input-group.mdx +0 -20
- package/src/components/input-group/input-group.tsx +0 -44
- package/src/components/kbd/index.ts +0 -1
- package/src/components/kbd/kbd.mdx +0 -18
- package/src/components/kbd/kbd.recipe.ts +0 -57
- package/src/components/kbd/kbd.tsx +0 -1
- package/src/components/link/index.ts +0 -2
- package/src/components/link/link.mdx +0 -77
- package/src/components/link/link.recipe.ts +0 -52
- package/src/components/link/link.slots.tsx +0 -29
- package/src/components/link/link.stories.tsx +0 -204
- package/src/components/link/link.tsx +0 -38
- package/src/components/link/link.types.tsx +0 -26
- package/src/components/list/index.ts +0 -1
- package/src/components/list/list.mdx +0 -18
- package/src/components/list/list.recipe.ts +0 -68
- package/src/components/list/list.tsx +0 -9
- package/src/components/loading-spinner/index.ts +0 -2
- package/src/components/loading-spinner/loading-spinner.mdx +0 -92
- package/src/components/loading-spinner/loading-spinner.recipe.tsx +0 -70
- package/src/components/loading-spinner/loading-spinner.slots.tsx +0 -38
- package/src/components/loading-spinner/loading-spinner.stories.tsx +0 -97
- package/src/components/loading-spinner/loading-spinner.tsx +0 -50
- package/src/components/loading-spinner/loading-spinner.types.tsx +0 -21
- package/src/components/nimbus-provider/color-mode.tsx +0 -32
- package/src/components/nimbus-provider/index.ts +0 -2
- package/src/components/nimbus-provider/nimbus-provider.mdx +0 -21
- package/src/components/nimbus-provider/nimbus-provider.tsx +0 -51
- package/src/components/select/components/select.clear-button.tsx +0 -31
- package/src/components/select/components/select.option-group.tsx +0 -48
- package/src/components/select/components/select.option.tsx +0 -21
- package/src/components/select/components/select.options.tsx +0 -23
- package/src/components/select/components/select.root.tsx +0 -81
- package/src/components/select/index.ts +0 -2
- package/src/components/select/select.mdx +0 -170
- package/src/components/select/select.recipe.tsx +0 -216
- package/src/components/select/select.slots.tsx +0 -58
- package/src/components/select/select.stories.tsx +0 -841
- package/src/components/select/select.tsx +0 -18
- package/src/components/select/select.types.tsx +0 -37
- package/src/components/simple-grid/index.ts +0 -1
- package/src/components/simple-grid/simple-grid.mdx +0 -133
- package/src/components/simple-grid/simple-grid.stories.tsx +0 -143
- package/src/components/simple-grid/simple-grid.tsx +0 -31
- package/src/components/stack/index.ts +0 -1
- package/src/components/stack/stack.mdx +0 -88
- package/src/components/stack/stack.stories.tsx +0 -82
- package/src/components/stack/stack.tsx +0 -15
- package/src/components/table/index.ts +0 -1
- package/src/components/table/table.mdx +0 -23
- package/src/components/table/table.recipe.ts +0 -170
- package/src/components/table/table.tsx +0 -43
- package/src/components/text/index.ts +0 -1
- package/src/components/text/text.mdx +0 -244
- package/src/components/text/text.tsx +0 -23
- package/src/components/text-input/index.ts +0 -2
- package/src/components/text-input/text-input.mdx +0 -118
- package/src/components/text-input/text-input.recipe.tsx +0 -68
- package/src/components/text-input/text-input.slots.tsx +0 -24
- package/src/components/text-input/text-input.stories.tsx +0 -282
- package/src/components/text-input/text-input.tsx +0 -39
- package/src/components/text-input/text-input.types.ts +0 -7
- package/src/components/toggle-button-group/components/toggle-button-group.button.tsx +0 -14
- package/src/components/toggle-button-group/components/toggle-button-group.root.tsx +0 -15
- package/src/components/toggle-button-group/index.ts +0 -2
- package/src/components/toggle-button-group/toggle-button-group.mdx +0 -94
- package/src/components/toggle-button-group/toggle-button-group.recipe.tsx +0 -64
- package/src/components/toggle-button-group/toggle-button-group.slots.tsx +0 -26
- package/src/components/toggle-button-group/toggle-button-group.stories.tsx +0 -311
- package/src/components/toggle-button-group/toggle-button-group.tsx +0 -12
- package/src/components/toggle-button-group/toggle-button-group.types.tsx +0 -62
- package/src/components/tooltip/index.ts +0 -4
- package/src/components/tooltip/make-element-focusable.stories.tsx +0 -56
- package/src/components/tooltip/make-element-focusable.tsx +0 -57
- package/src/components/tooltip/tooltip-trigger.stories.tsx +0 -157
- package/src/components/tooltip/tooltip-trigger.tsx +0 -15
- package/src/components/tooltip/tooltip.mdx +0 -48
- package/src/components/tooltip/tooltip.recipe.ts +0 -26
- package/src/components/tooltip/tooltip.slots.ts +0 -35
- package/src/components/tooltip/tooltip.stories.tsx +0 -139
- package/src/components/tooltip/tooltip.tsx +0 -31
- package/src/components/tooltip/tooltip.types.ts +0 -44
- package/src/components/visually-hidden/index.ts +0 -1
- package/src/components/visually-hidden/visually-hidden.mdx +0 -61
- package/src/components/visually-hidden/visually-hidden.stories.tsx +0 -124
- package/src/components/visually-hidden/visually-hidden.tsx +0 -18
- package/src/docs/accessibility.mdx +0 -21
- package/src/docs/background.mdx +0 -154
- package/src/docs/border.mdx +0 -226
- package/src/docs/changelog.mdx +0 -17
- package/src/docs/components-layout.mdx +0 -22
- package/src/docs/components.mdx +0 -17
- package/src/docs/data-display.mdx +0 -23
- package/src/docs/display.mdx +0 -55
- package/src/docs/effects.mdx +0 -73
- package/src/docs/feedback.mdx +0 -22
- package/src/docs/filters.mdx +0 -268
- package/src/docs/flex-and-grid.mdx +0 -445
- package/src/docs/forms.mdx +0 -22
- package/src/docs/generated/index.mdx +0 -16
- package/src/docs/getting-started.mdx +0 -17
- package/src/docs/home.mdx +0 -56
- package/src/docs/hooks.mdx +0 -16
- package/src/docs/inputs.mdx +0 -21
- package/src/docs/installation.mdx +0 -60
- package/src/docs/interactivity.mdx +0 -278
- package/src/docs/known-issues.mdx +0 -19
- package/src/docs/layout.mdx +0 -301
- package/src/docs/list.mdx +0 -82
- package/src/docs/markdown.mdx +0 -234
- package/src/docs/media.mdx +0 -22
- package/src/docs/naivgation.mdx +0 -22
- package/src/docs/playground.mdx +0 -16
- package/src/docs/rfcs-component-structure-rfcs.mdx +0 -17
- package/src/docs/rfcs-component-structure.mdx +0 -74
- package/src/docs/rfcs-hook-structure.mdx +0 -59
- package/src/docs/sizing.mdx +0 -210
- package/src/docs/spacing.mdx +0 -193
- package/src/docs/style-props-typography.mdx +0 -373
- package/src/docs/style-props.mdx +0 -15
- package/src/docs/svg.mdx +0 -58
- package/src/docs/tables.mdx +0 -95
- package/src/docs/toc.mdx +0 -39
- package/src/docs/tokens/animations.mdx +0 -68
- package/src/docs/tokens/aspect-ratios.mdx +0 -21
- package/src/docs/tokens/blurs.mdx +0 -20
- package/src/docs/tokens/borders.mdx +0 -25
- package/src/docs/tokens/breakpoints.mdx +0 -35
- package/src/docs/tokens/colors.mdx +0 -86
- package/src/docs/tokens/cursors.mdx +0 -21
- package/src/docs/tokens/radii.mdx +0 -23
- package/src/docs/tokens/shadows.mdx +0 -21
- package/src/docs/tokens/sizes.mdx +0 -54
- package/src/docs/tokens/spacing.mdx +0 -35
- package/src/docs/tokens/typography.mdx +0 -61
- package/src/docs/tokens/z-indices.mdx +0 -23
- package/src/docs/tokens-other.mdx +0 -17
- package/src/docs/tokens.mdx +0 -16
- package/src/docs/transforms.mdx +0 -150
- package/src/docs/transitions.mdx +0 -164
- package/src/docs/typography.mdx +0 -17
- package/src/docs/utilities.mdx +0 -17
- package/src/hooks/index.ts +0 -2
- package/src/hooks/use-copy-to-clipboard/use-copy-to-clipboard.mdx +0 -54
- package/src/hooks/use-copy-to-clipboard/use-copy-to-clipboard.ts +0 -1
- package/src/hooks/use-hotkeys/use-hotkeys.mdx +0 -48
- package/src/hooks/use-hotkeys/use-hotkeys.stories.tsx +0 -69
- package/src/hooks/use-hotkeys/use-hotkeys.ts +0 -1
- package/src/index.ts +0 -3
- package/src/test/utils.tsx +0 -20
- package/src/theme/animation-styles.ts +0 -52
- package/src/theme/breakpoints.ts +0 -32
- package/src/theme/global-css.ts +0 -53
- package/src/theme/index.ts +0 -35
- package/src/theme/keyframes.ts +0 -192
- package/src/theme/layer-styles.ts +0 -12
- package/src/theme/recipes/index.ts +0 -21
- package/src/theme/semantic-tokens/colors.ts +0 -55
- package/src/theme/semantic-tokens/index.ts +0 -9
- package/src/theme/semantic-tokens/radii.ts +0 -3
- package/src/theme/semantic-tokens/shadows.ts +0 -4
- package/src/theme/slot-recipes/index.ts +0 -15
- package/src/theme/text-styles.ts +0 -8
- package/src/theme/tokens/animations.ts +0 -4
- package/src/theme/tokens/aspect-ratios.ts +0 -5
- package/src/theme/tokens/blurs.ts +0 -5
- package/src/theme/tokens/borders.ts +0 -4
- package/src/theme/tokens/colors.ts +0 -8
- package/src/theme/tokens/cursor.ts +0 -4
- package/src/theme/tokens/durations.ts +0 -4
- package/src/theme/tokens/easings.ts +0 -4
- package/src/theme/tokens/font-sizes.ts +0 -4
- package/src/theme/tokens/font-weights.ts +0 -4
- package/src/theme/tokens/fonts.ts +0 -4
- package/src/theme/tokens/index.ts +0 -57
- package/src/theme/tokens/letter-spacings.ts +0 -24
- package/src/theme/tokens/line-heights.ts +0 -4
- package/src/theme/tokens/radii.ts +0 -4
- package/src/theme/tokens/sizes.ts +0 -120
- package/src/theme/tokens/spacing.ts +0 -4
- package/src/theme/tokens/z-index.ts +0 -4
- package/src/utils/extractStyleProps.ts +0 -26
- package/src/utils/fixedForwardRef.ts +0 -17
- package/tsconfig.json +0 -38
- package/vite.config.ts +0 -54
- package/vitest.config.ts +0 -50
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useContext, useEffect } from "react";
|
|
2
|
-
import { AlertActions as AlertActionsSlot } from "../alert.slots";
|
|
3
|
-
import type { AlertActionsProps } from "../alert.types";
|
|
4
|
-
import { AlertContext } from "./alert.root";
|
|
5
|
-
|
|
6
|
-
const AlertActions = ({ children, ...props }: AlertActionsProps) => {
|
|
7
|
-
const context = useContext(AlertContext);
|
|
8
|
-
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (context) {
|
|
11
|
-
const slotElement = (
|
|
12
|
-
<AlertActionsSlot {...props}>{children}</AlertActionsSlot>
|
|
13
|
-
);
|
|
14
|
-
// Register it with the parent
|
|
15
|
-
context.setActions(slotElement);
|
|
16
|
-
|
|
17
|
-
// On unmount, remove it
|
|
18
|
-
return () => context.setActions(null);
|
|
19
|
-
}
|
|
20
|
-
}, [children, props]);
|
|
21
|
-
|
|
22
|
-
return null;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
AlertActions.displayName = "Alert.Actions";
|
|
26
|
-
|
|
27
|
-
export default AlertActions;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useContext, useEffect } from "react";
|
|
2
|
-
import { AlertDescription as AlertDescriptionSlot } from "../alert.slots";
|
|
3
|
-
import type { AlertDescriptionProps } from "../alert.types";
|
|
4
|
-
import { AlertContext } from "./alert.root";
|
|
5
|
-
|
|
6
|
-
const AlertDescription = ({ children, ...props }: AlertDescriptionProps) => {
|
|
7
|
-
const context = useContext(AlertContext);
|
|
8
|
-
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (context) {
|
|
11
|
-
const slotElement = (
|
|
12
|
-
<AlertDescriptionSlot {...props}>{children}</AlertDescriptionSlot>
|
|
13
|
-
);
|
|
14
|
-
// Register it with the parent
|
|
15
|
-
context.setDescription(slotElement);
|
|
16
|
-
|
|
17
|
-
// On unmount, remove it
|
|
18
|
-
return () => context.setDescription(null);
|
|
19
|
-
}
|
|
20
|
-
}, [children, props]);
|
|
21
|
-
|
|
22
|
-
return null;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
AlertDescription.displayName = "Alert.Description";
|
|
26
|
-
|
|
27
|
-
export default AlertDescription;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { useContext, useEffect } from "react";
|
|
2
|
-
import { AlertDismissButton as AlertDismissButtonSlot } from "../alert.slots";
|
|
3
|
-
import type { AlertDismissButtonProps } from "../alert.types";
|
|
4
|
-
import { Clear } from "@commercetools/nimbus-icons";
|
|
5
|
-
import { IconButton } from "../../icon-button";
|
|
6
|
-
import { AlertContext } from "./alert.root";
|
|
7
|
-
|
|
8
|
-
const AlertDismissButton = ({
|
|
9
|
-
children,
|
|
10
|
-
...props
|
|
11
|
-
}: AlertDismissButtonProps) => {
|
|
12
|
-
const context = useContext(AlertContext);
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (context) {
|
|
16
|
-
const slotElement = (
|
|
17
|
-
<AlertDismissButtonSlot>
|
|
18
|
-
<IconButton
|
|
19
|
-
aria-label="Dismiss"
|
|
20
|
-
{...props}
|
|
21
|
-
variant="ghost"
|
|
22
|
-
size="2xs"
|
|
23
|
-
>
|
|
24
|
-
<Clear role="img" />
|
|
25
|
-
</IconButton>
|
|
26
|
-
</AlertDismissButtonSlot>
|
|
27
|
-
);
|
|
28
|
-
// Register it with the parent
|
|
29
|
-
context.setDismiss(slotElement);
|
|
30
|
-
|
|
31
|
-
// On unmount, remove it
|
|
32
|
-
return () => context.setDismiss(null);
|
|
33
|
-
}
|
|
34
|
-
}, [children, props]);
|
|
35
|
-
|
|
36
|
-
return null;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
AlertDismissButton.displayName = "Alert.DismissButton";
|
|
40
|
-
|
|
41
|
-
export default AlertDismissButton;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
forwardRef,
|
|
4
|
-
useMemo,
|
|
5
|
-
useState,
|
|
6
|
-
type ReactNode,
|
|
7
|
-
} from "react";
|
|
8
|
-
import { AlertRoot as AlertRootSlot, AlertIcon } from "../alert.slots";
|
|
9
|
-
import type { AlertProps, AlertRootComponent } from "../alert.types";
|
|
10
|
-
import { Box } from "../../box";
|
|
11
|
-
import { Stack } from "../../stack";
|
|
12
|
-
import {
|
|
13
|
-
CheckCircleOutline,
|
|
14
|
-
ErrorOutline,
|
|
15
|
-
Info,
|
|
16
|
-
WarningAmber,
|
|
17
|
-
} from "@commercetools/nimbus-icons";
|
|
18
|
-
|
|
19
|
-
const getIconFromTone = (tone: AlertProps["tone"]) => {
|
|
20
|
-
switch (tone) {
|
|
21
|
-
case "critical":
|
|
22
|
-
return <ErrorOutline />;
|
|
23
|
-
case "info":
|
|
24
|
-
return <Info />;
|
|
25
|
-
case "warning":
|
|
26
|
-
return <WarningAmber />;
|
|
27
|
-
case "positive":
|
|
28
|
-
return <CheckCircleOutline />;
|
|
29
|
-
default:
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type AlertContextValue = {
|
|
35
|
-
setTitle: (title: ReactNode) => void;
|
|
36
|
-
setDescription: (description: ReactNode) => void;
|
|
37
|
-
setActions: (actions: ReactNode) => void;
|
|
38
|
-
setDismiss: (dismiss: ReactNode) => void;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const AlertContext = createContext<AlertContextValue | undefined>(
|
|
42
|
-
undefined
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Alert
|
|
47
|
-
* ============================================================
|
|
48
|
-
* Provides feedback to the user about the status of an action or system event
|
|
49
|
-
*/
|
|
50
|
-
const AlertRoot: AlertRootComponent = forwardRef<HTMLDivElement, AlertProps>(
|
|
51
|
-
({ children, ...props }, ref) => {
|
|
52
|
-
const [titleNode, setTitle] = useState<ReactNode>(null);
|
|
53
|
-
const [descriptionNode, setDescription] = useState<ReactNode>(null);
|
|
54
|
-
const [actionsNode, setActions] = useState<ReactNode>(null);
|
|
55
|
-
const [dismissNode, setDismiss] = useState<ReactNode>(null);
|
|
56
|
-
|
|
57
|
-
// Memoize the context value so we don't cause unnecessary re-renders
|
|
58
|
-
const contextValue = useMemo(
|
|
59
|
-
() => ({
|
|
60
|
-
setTitle,
|
|
61
|
-
setDescription,
|
|
62
|
-
setActions,
|
|
63
|
-
setDismiss,
|
|
64
|
-
}),
|
|
65
|
-
[setTitle, setDescription, setActions, setDismiss]
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<AlertContext.Provider value={contextValue}>
|
|
70
|
-
<AlertRootSlot ref={ref} {...props} role="alert">
|
|
71
|
-
<AlertIcon alignItems="flex-start">
|
|
72
|
-
{getIconFromTone(props.tone)}
|
|
73
|
-
</AlertIcon>
|
|
74
|
-
<Stack flex="1" gap="200">
|
|
75
|
-
<Box>
|
|
76
|
-
{titleNode}
|
|
77
|
-
{descriptionNode}
|
|
78
|
-
</Box>
|
|
79
|
-
{actionsNode}
|
|
80
|
-
</Stack>
|
|
81
|
-
{dismissNode}
|
|
82
|
-
|
|
83
|
-
{children}
|
|
84
|
-
</AlertRootSlot>
|
|
85
|
-
</AlertContext.Provider>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
AlertRoot.displayName = "Alert.Root";
|
|
91
|
-
|
|
92
|
-
export default AlertRoot;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useContext, useEffect } from "react";
|
|
2
|
-
import { AlertTitle as AlertTitleSlot } from "../alert.slots";
|
|
3
|
-
import type { AlertTitleProps } from "../alert.types";
|
|
4
|
-
import { AlertContext } from "./alert.root";
|
|
5
|
-
|
|
6
|
-
const AlertTitle = ({ children, ...props }: AlertTitleProps) => {
|
|
7
|
-
const context = useContext(AlertContext);
|
|
8
|
-
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (context) {
|
|
11
|
-
const slotElement = (
|
|
12
|
-
<AlertTitleSlot {...props} fontWeight="600">
|
|
13
|
-
{children}
|
|
14
|
-
</AlertTitleSlot>
|
|
15
|
-
);
|
|
16
|
-
// Register it with the parent
|
|
17
|
-
context.setTitle(slotElement);
|
|
18
|
-
|
|
19
|
-
// On unmount, remove it
|
|
20
|
-
return () => context.setTitle(null);
|
|
21
|
-
}
|
|
22
|
-
}, [children, props]);
|
|
23
|
-
|
|
24
|
-
return null;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
AlertTitle.displayName = "Alert.Title";
|
|
28
|
-
|
|
29
|
-
export default AlertTitle;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: Components-Avatar
|
|
3
|
-
title: Avatar
|
|
4
|
-
description: >-
|
|
5
|
-
A reusable Avatar component to display user profile pictures or initials that
|
|
6
|
-
is flexible and customizable for various use cases.
|
|
7
|
-
documentState: InitialDraft
|
|
8
|
-
order: 999
|
|
9
|
-
menu:
|
|
10
|
-
- Components
|
|
11
|
-
- Media
|
|
12
|
-
- Avatar
|
|
13
|
-
tags:
|
|
14
|
-
- component
|
|
15
|
-
figmaLink: >-
|
|
16
|
-
https://www.figma.com/design/AvtPX6g7OGGCRvNlatGOIY/New-Design-System?node-id=180-1106&t=MVbo0ZHDE08wKshT-0
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
# Avatar
|
|
20
|
-
|
|
21
|
-
A reusable Avatar component that displays user profile pictures or initials.
|
|
22
|
-
It's accessible, keyboard-navigable, and follows WCAG guidelines.
|
|
23
|
-
|
|
24
|
-
## Basic Usage
|
|
25
|
-
|
|
26
|
-
Use the Avatar component to represent a user with either their profile picture
|
|
27
|
-
or initials.
|
|
28
|
-
|
|
29
|
-
```jsx-live
|
|
30
|
-
const App = () => (
|
|
31
|
-
<Stack direction="horizontal">
|
|
32
|
-
<Avatar firstName="John" lastName="Doe" src="https://thispersondoesnotexist.com/ " />
|
|
33
|
-
<Avatar firstName="Jane" lastName="Smith" /> {/* Shows initials when no image */}
|
|
34
|
-
</Stack>
|
|
35
|
-
)
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Features
|
|
39
|
-
|
|
40
|
-
### Sizes
|
|
41
|
-
|
|
42
|
-
Available in multiple sizes to suit different contexts:
|
|
43
|
-
|
|
44
|
-
```jsx-live
|
|
45
|
-
const App = () => {
|
|
46
|
-
const sizes = ["md", "xs", "2xs"];
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<Stack direction="horizontal" alignItems="center">
|
|
50
|
-
{sizes.map(size => (
|
|
51
|
-
<Avatar
|
|
52
|
-
key={size}
|
|
53
|
-
size={size}
|
|
54
|
-
firstName="John"
|
|
55
|
-
lastName="Doe"
|
|
56
|
-
src="https://thispersondoesnotexist.com/ "
|
|
57
|
-
/>
|
|
58
|
-
))}
|
|
59
|
-
</Stack>
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Fallback Behavior
|
|
65
|
-
|
|
66
|
-
The component handles various scenarios gracefully:
|
|
67
|
-
|
|
68
|
-
- Shows initials when no image is provided
|
|
69
|
-
|
|
70
|
-
```jsx-live
|
|
71
|
-
const App = () => (
|
|
72
|
-
<Stack direction="horizontal">
|
|
73
|
-
<Avatar firstName="John" lastName="Doe"/> {/* Shows JD */}
|
|
74
|
-
</Stack>
|
|
75
|
-
)
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Props
|
|
79
|
-
|
|
80
|
-
<PropTable id="Avatar" />
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { defineRecipe } from "@chakra-ui/react";
|
|
2
|
-
|
|
3
|
-
export const avatarRecipe = defineRecipe({
|
|
4
|
-
className: "avatar",
|
|
5
|
-
base: {
|
|
6
|
-
display: "inline-flex",
|
|
7
|
-
alignItems: "center",
|
|
8
|
-
justifyContent: "center",
|
|
9
|
-
verticalAlign: "middle",
|
|
10
|
-
overflow: "hidden",
|
|
11
|
-
userSelect: "none",
|
|
12
|
-
borderRadius: "full",
|
|
13
|
-
flexShrink: 0,
|
|
14
|
-
fontWeight: "600",
|
|
15
|
-
backgroundColor: "colorPalette.3",
|
|
16
|
-
colorPalette: "primary",
|
|
17
|
-
color: "colorPalette.11",
|
|
18
|
-
focusVisibleRing: "outside",
|
|
19
|
-
"button&": {
|
|
20
|
-
cursor: "button",
|
|
21
|
-
},
|
|
22
|
-
_disabled: {
|
|
23
|
-
layerStyle: "disabled",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
variants: {
|
|
27
|
-
size: {
|
|
28
|
-
md: { width: 1000, height: 1000, textStyle: "sm" },
|
|
29
|
-
xs: { width: 800, height: 800, textStyle: "xs" },
|
|
30
|
-
"2xs": { width: 600, height: 600, textStyle: "xs" },
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
defaultVariants: {
|
|
34
|
-
size: "md",
|
|
35
|
-
},
|
|
36
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type HTMLChakraProps,
|
|
3
|
-
type RecipeProps,
|
|
4
|
-
type UnstyledProp,
|
|
5
|
-
createRecipeContext,
|
|
6
|
-
} from "@chakra-ui/react";
|
|
7
|
-
import { avatarRecipe } from "./avatar.recipe";
|
|
8
|
-
|
|
9
|
-
interface AvatarRecipeProps extends RecipeProps<"div">, UnstyledProp {}
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
12
|
-
export interface AvatarRootProps
|
|
13
|
-
extends HTMLChakraProps<"div", AvatarRecipeProps> {}
|
|
14
|
-
const { withContext } = createRecipeContext({ recipe: avatarRecipe });
|
|
15
|
-
|
|
16
|
-
export const AvatarRoot = withContext<HTMLElement, AvatarRootProps>("figure");
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import { Avatar } from "./avatar";
|
|
3
|
-
import type { AvatarProps } from "./avatar.types";
|
|
4
|
-
import { within, expect } from "@storybook/test";
|
|
5
|
-
import { Button, Stack } from "@/components";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Storybook metadata configuration
|
|
9
|
-
* - title: determines the location in the sidebar
|
|
10
|
-
* - component: references the component being documented
|
|
11
|
-
*/
|
|
12
|
-
const meta: Meta<typeof Avatar> = {
|
|
13
|
-
title: "components/Avatar",
|
|
14
|
-
component: Avatar,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default meta;
|
|
18
|
-
type Story = StoryObj<typeof Avatar>;
|
|
19
|
-
|
|
20
|
-
const sizes: AvatarProps["size"][] = ["md", "xs", "2xs"];
|
|
21
|
-
|
|
22
|
-
const colorPalettes: AvatarProps["colorPalette"][] = [
|
|
23
|
-
"red",
|
|
24
|
-
"green",
|
|
25
|
-
"blue",
|
|
26
|
-
"amber",
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
const avatarImg = "https://thispersondoesnotexist.com/ ";
|
|
30
|
-
|
|
31
|
-
export const Base: Story = {
|
|
32
|
-
args: {
|
|
33
|
-
src: avatarImg,
|
|
34
|
-
["aria-label"]: "avatar",
|
|
35
|
-
alt: "avatar",
|
|
36
|
-
},
|
|
37
|
-
play: async ({ canvasElement, step }) => {
|
|
38
|
-
const canvas = within(canvasElement);
|
|
39
|
-
const avatar = canvas.getByLabelText("avatar");
|
|
40
|
-
|
|
41
|
-
await step("Uses a <figure> element by default", async () => {
|
|
42
|
-
await expect(avatar.tagName).toBe("FIGURE");
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const Sizes: Story = {
|
|
48
|
-
args: {
|
|
49
|
-
src: avatarImg,
|
|
50
|
-
["aria-label"]: "avatar",
|
|
51
|
-
alt: "avatar",
|
|
52
|
-
},
|
|
53
|
-
render: (args) => {
|
|
54
|
-
return (
|
|
55
|
-
<Stack direction="row" gap="400" alignItems="center">
|
|
56
|
-
{sizes.map((size) => (
|
|
57
|
-
<Avatar key={size as string} {...args} size={size} alt="avatar" />
|
|
58
|
-
))}
|
|
59
|
-
</Stack>
|
|
60
|
-
);
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const BaseWithInitials: Story = {
|
|
65
|
-
args: {
|
|
66
|
-
firstName: "John",
|
|
67
|
-
lastName: "Doe",
|
|
68
|
-
["aria-label"]: "avatar",
|
|
69
|
-
alt: "avatar",
|
|
70
|
-
},
|
|
71
|
-
play: async ({ canvasElement, step }) => {
|
|
72
|
-
const canvas = within(canvasElement);
|
|
73
|
-
const avatar = canvas.getByLabelText("avatar");
|
|
74
|
-
await step(
|
|
75
|
-
"Take first letters of first and last name to make initials",
|
|
76
|
-
async () => {
|
|
77
|
-
await expect(avatar).toHaveTextContent("JD");
|
|
78
|
-
}
|
|
79
|
-
);
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const SizesWithInitials: Story = {
|
|
84
|
-
args: {
|
|
85
|
-
firstName: "Michael",
|
|
86
|
-
lastName: "Douglas",
|
|
87
|
-
["aria-label"]: "avatar",
|
|
88
|
-
alt: "avatar",
|
|
89
|
-
},
|
|
90
|
-
render: (args) => {
|
|
91
|
-
return (
|
|
92
|
-
<Stack direction="row" gap="400" alignItems="center">
|
|
93
|
-
{sizes.map((size) => (
|
|
94
|
-
<Avatar key={size as string} {...args} size={size} alt="avatar" />
|
|
95
|
-
))}
|
|
96
|
-
</Stack>
|
|
97
|
-
);
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const Colors: Story = {
|
|
102
|
-
args: {
|
|
103
|
-
firstName: "Michael",
|
|
104
|
-
lastName: "Douglas",
|
|
105
|
-
["aria-label"]: "avatar",
|
|
106
|
-
alt: "avatar",
|
|
107
|
-
},
|
|
108
|
-
render: (args) => {
|
|
109
|
-
return (
|
|
110
|
-
<Stack direction="row" gap="400" alignItems="center">
|
|
111
|
-
{colorPalettes.map((colorPalette) => (
|
|
112
|
-
<Avatar
|
|
113
|
-
key={colorPalette as string}
|
|
114
|
-
{...args}
|
|
115
|
-
colorPalette={colorPalette}
|
|
116
|
-
alt="avatar"
|
|
117
|
-
/>
|
|
118
|
-
))}
|
|
119
|
-
</Stack>
|
|
120
|
-
);
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export const InAButton: Story = {
|
|
125
|
-
args: {
|
|
126
|
-
src: avatarImg,
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
render(args) {
|
|
130
|
-
return (
|
|
131
|
-
<Button unstyled asChild>
|
|
132
|
-
<Avatar {...args} as="button" />
|
|
133
|
-
</Button>
|
|
134
|
-
);
|
|
135
|
-
},
|
|
136
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { forwardRef } from "react";
|
|
2
|
-
import { Image } from "@chakra-ui/react";
|
|
3
|
-
import { type AvatarProps } from "./avatar.types";
|
|
4
|
-
import { AvatarRoot } from "./avatar.slots.tsx";
|
|
5
|
-
|
|
6
|
-
function getInitials(firstName: string, lastName: string) {
|
|
7
|
-
return (
|
|
8
|
-
firstName.split("")[0].toUpperCase() + lastName.split("")[0].toUpperCase()
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const Avatar = forwardRef<HTMLDivElement, AvatarProps>((props, ref) => {
|
|
13
|
-
const { firstName, lastName, src, alt, ...rest } = props;
|
|
14
|
-
|
|
15
|
-
const fullName = `${firstName} ${lastName}`;
|
|
16
|
-
|
|
17
|
-
const sharedProps = {
|
|
18
|
-
"aria-label": `${fullName} avatar`,
|
|
19
|
-
ref,
|
|
20
|
-
...rest,
|
|
21
|
-
};
|
|
22
|
-
return (
|
|
23
|
-
<AvatarRoot {...sharedProps}>
|
|
24
|
-
{src ? (
|
|
25
|
-
// TODO: implement more robust error handling for image
|
|
26
|
-
<Image src={src} alt={alt || fullName} />
|
|
27
|
-
) : (
|
|
28
|
-
getInitials(firstName, lastName)
|
|
29
|
-
)}
|
|
30
|
-
</AvatarRoot>
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
Avatar.displayName = "Avatar";
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { HTMLAttributes } from "react";
|
|
2
|
-
import type { RecipeVariantProps } from "@chakra-ui/react";
|
|
3
|
-
import { avatarRecipe } from "./avatar.recipe.tsx";
|
|
4
|
-
import type { AvatarRootProps } from "./avatar.slots";
|
|
5
|
-
export interface AvatarComponentProps
|
|
6
|
-
extends HTMLAttributes<HTMLDivElement>,
|
|
7
|
-
RecipeVariantProps<typeof avatarRecipe> {
|
|
8
|
-
/**
|
|
9
|
-
* The first name used to show initials
|
|
10
|
-
*/
|
|
11
|
-
firstName: string;
|
|
12
|
-
/**
|
|
13
|
-
* The last name used to show initials
|
|
14
|
-
*/
|
|
15
|
-
lastName: string;
|
|
16
|
-
/**
|
|
17
|
-
* The image URL
|
|
18
|
-
*/
|
|
19
|
-
src?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Alt text for the avatar image
|
|
22
|
-
*/
|
|
23
|
-
alt?: string;
|
|
24
|
-
/**
|
|
25
|
-
* If the avatar is disabled
|
|
26
|
-
*/
|
|
27
|
-
isDisabled?: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type FunctionalAvatarProps = AvatarRootProps & AvatarComponentProps;
|
|
31
|
-
export interface AvatarProps extends FunctionalAvatarProps {
|
|
32
|
-
children?: React.ReactNode;
|
|
33
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: Components-Badge
|
|
3
|
-
title: Badge
|
|
4
|
-
description: To display small status indicators or labels.
|
|
5
|
-
documentState: InitialDraft
|
|
6
|
-
order: 999
|
|
7
|
-
menu:
|
|
8
|
-
- Components
|
|
9
|
-
- Badge
|
|
10
|
-
tags:
|
|
11
|
-
- component
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Badge
|
|
15
|
-
|
|
16
|
-
To display small status indicators or labels.
|
|
17
|
-
|
|
18
|
-
## Basic Usage
|
|
19
|
-
|
|
20
|
-
[Explain the basic usage / usecase of the component].
|
|
21
|
-
|
|
22
|
-
```jsx-live
|
|
23
|
-
const App = () => <Badge>I am Badge!</Badge>
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### Sizes
|
|
27
|
-
|
|
28
|
-
Available sizes.
|
|
29
|
-
|
|
30
|
-
```jsx-live
|
|
31
|
-
const App = () => {
|
|
32
|
-
|
|
33
|
-
const sizes = ['md', 'xs', '2xs'];
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<Stack direction="horizontal" alignItems="center">
|
|
37
|
-
{sizes.map(size => (
|
|
38
|
-
<Badge key={size} size={size}>'{size}' Badge</Badge>
|
|
39
|
-
))}
|
|
40
|
-
</Stack>
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### Variants
|
|
46
|
-
|
|
47
|
-
Available variants.
|
|
48
|
-
|
|
49
|
-
```jsx-live
|
|
50
|
-
const App = () => {
|
|
51
|
-
|
|
52
|
-
const variants = ['solid', 'subtle', 'outline', 'ghost', 'plain'];
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<Stack direction="horizontal">
|
|
56
|
-
{variants.map(variant => (
|
|
57
|
-
<Badge key={variant} variant={variant}>'{variant}' Badge</Badge>
|
|
58
|
-
))}
|
|
59
|
-
</Stack>
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Colors
|
|
65
|
-
|
|
66
|
-
[Explain usage with different colors/semantics.]
|
|
67
|
-
|
|
68
|
-
```jsx-live
|
|
69
|
-
const App = () => {
|
|
70
|
-
const variants = ["solid", "subtle", "outline", "ghost", "link", "plain"];
|
|
71
|
-
const colors = ["neutral", "primary", "info", "success", "danger", "error"];
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<Stack>
|
|
75
|
-
{colors.map((color) => (
|
|
76
|
-
<Stack key={color} direction="horizontal">
|
|
77
|
-
{variants.map((variant) => (
|
|
78
|
-
<Badge colorPalette={color} key={variant} variant={variant}>
|
|
79
|
-
'{variant}' Badge
|
|
80
|
-
</Badge>
|
|
81
|
-
))}
|
|
82
|
-
</Stack>
|
|
83
|
-
))}
|
|
84
|
-
</Stack>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Props
|
|
90
|
-
|
|
91
|
-
<PropTable id="Badge" />
|