@appdirect/design-system 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/dist/Buttons/ActionIcon.tsx +37 -0
- package/dist/Buttons/Button.module.css +5 -0
- package/dist/Buttons/Button.tsx +124 -0
- package/dist/Buttons/CloseButton.tsx +83 -0
- package/dist/Buttons/index.ts +20 -0
- package/dist/Combobox/AutocompleteClearable.tsx +128 -0
- package/dist/Combobox/Combobox.tsx +37 -0
- package/dist/Combobox/Multiselect.tsx +158 -0
- package/dist/Combobox/SearchableSelect.tsx +131 -0
- package/dist/Combobox/Select.tsx +154 -0
- package/dist/Combobox/index.ts +20 -0
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +280 -0
- package/dist/ComplexComponents/DashboardWidget/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +177 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +35 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +74 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +358 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/DateRangeFilter.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterRenderer.tsx +71 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterSystem.tsx +158 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/MultiSelectFilter.tsx +79 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/SingleSelectFilter.tsx +65 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/index.ts +70 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/types.ts +140 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +76 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +73 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +50 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +788 -0
- package/dist/ComplexComponents/DataTable/DataTable.tsx +582 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +29 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +57 -0
- package/dist/ComplexComponents/DataTable/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/translations/en.ts +115 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +23 -0
- package/dist/ComplexComponents/KeyInsight/KeyInsights.tsx +221 -0
- package/dist/ComplexComponents/KeyInsight/index.ts +2 -0
- package/dist/ComplexComponents/NameValue/NameValue.tsx +175 -0
- package/dist/ComplexComponents/NameValue/NameValueItem.tsx +100 -0
- package/dist/ComplexComponents/NameValue/index.ts +4 -0
- package/dist/ComplexComponents/PageContentHeader/DescriptionBlock.tsx +65 -0
- package/dist/ComplexComponents/PageContentHeader/PageContentHeader.tsx +383 -0
- package/dist/ComplexComponents/PageContentHeader/index.ts +4 -0
- package/dist/ComplexComponents/Utilities/CopyButton.tsx +82 -0
- package/dist/ComplexComponents/Utilities/index.ts +2 -0
- package/dist/DataDisplay/Alert.tsx +130 -0
- package/dist/DataDisplay/Avatar.tsx +216 -0
- package/dist/DataDisplay/Badge.tsx +119 -0
- package/dist/DataDisplay/Card.module.css +26 -0
- package/dist/DataDisplay/Card.tsx +163 -0
- package/dist/DataDisplay/Chip.tsx +66 -0
- package/dist/DataDisplay/Indicator.tsx +122 -0
- package/dist/DataDisplay/List.tsx +90 -0
- package/dist/DataDisplay/Pill.tsx +125 -0
- package/dist/DataDisplay/Progress.tsx +77 -0
- package/dist/DataDisplay/Table.tsx +57 -0
- package/dist/DataDisplay/ThemeIcon.tsx +67 -0
- package/dist/DataDisplay/index.ts +41 -0
- package/dist/Inputs/Checkbox.tsx +94 -0
- package/dist/Inputs/ColorInput.tsx +124 -0
- package/dist/Inputs/DropZone.tsx +78 -0
- package/dist/Inputs/FileInput.tsx +120 -0
- package/dist/Inputs/NumberInput.tsx +125 -0
- package/dist/Inputs/Radio.tsx +86 -0
- package/dist/Inputs/RadioGroup.tsx +90 -0
- package/dist/Inputs/SegmentedControl.tsx +64 -0
- package/dist/Inputs/Slider.tsx +69 -0
- package/dist/Inputs/Switch.tsx +67 -0
- package/dist/Inputs/TextArea.tsx +126 -0
- package/dist/Inputs/TextInput.tsx +167 -0
- package/dist/Inputs/index.ts +51 -0
- package/dist/Layout/Box.tsx +82 -0
- package/dist/Layout/Center.tsx +17 -0
- package/dist/Layout/Container.tsx +17 -0
- package/dist/Layout/Flex.tsx +18 -0
- package/dist/Layout/Grid.tsx +31 -0
- package/dist/Layout/Group.tsx +54 -0
- package/dist/Layout/Inline.tsx +86 -0
- package/dist/Layout/SimpleGrid.tsx +50 -0
- package/dist/Layout/Stack.tsx +86 -0
- package/dist/Layout/index.ts +29 -0
- package/dist/Misc/Divider.tsx +27 -0
- package/dist/Misc/Paper.tsx +47 -0
- package/dist/Misc/index.ts +15 -0
- package/dist/Navigation/Breadcrumb.tsx +138 -0
- package/dist/Navigation/NavLink.tsx +37 -0
- package/dist/Navigation/Stepper.tsx +17 -0
- package/dist/Navigation/Tabs.tsx +29 -0
- package/dist/Navigation/index.ts +17 -0
- package/dist/Overlays/Drawer.tsx +123 -0
- package/dist/Overlays/Menu.tsx +192 -0
- package/dist/Overlays/Modal.tsx +159 -0
- package/dist/Overlays/Popover.tsx +319 -0
- package/dist/Overlays/Tooltip.tsx +131 -0
- package/dist/Overlays/index.ts +19 -0
- package/dist/Shell/AppShellLayout.tsx +56 -0
- package/dist/Shell/HeaderBar.tsx +26 -0
- package/dist/Shell/SidebarNav.tsx +47 -0
- package/dist/Shell/SidebarNavLink.tsx +50 -0
- package/dist/Shell/SingleColumnLayout.tsx +22 -0
- package/dist/Shell/TertiaryColumnLayout.tsx +32 -0
- package/dist/Shell/index.ts +17 -0
- package/dist/Typography/Code.tsx +27 -0
- package/dist/Typography/Kbd.tsx +87 -0
- package/dist/Typography/Text.tsx +27 -0
- package/dist/Typography/Title.tsx +34 -0
- package/dist/Typography/index.ts +21 -0
- package/dist/bin/ds-audit.js +521 -0
- package/dist/config.ts +226 -0
- package/dist/contracts/Alert.json +80 -0
- package/dist/contracts/Badge.json +78 -0
- package/dist/contracts/Box.json +52 -0
- package/dist/contracts/Button.json +111 -0
- package/dist/contracts/DataTable.json +68 -0
- package/dist/contracts/Grid.json +35 -0
- package/dist/contracts/Group.json +44 -0
- package/dist/contracts/Inline.json +73 -0
- package/dist/contracts/PageContentHeader.json +107 -0
- package/dist/contracts/Stack.json +62 -0
- package/dist/contracts/ds-component-contract.v1.json +23 -0
- package/dist/contracts/index.json +55 -0
- package/dist/css/foundations.css +703 -0
- package/dist/css/mantine.css +1797 -0
- package/dist/hooks/useTableHandlers.ts +179 -0
- package/dist/hooks/useTableRenderFunctions.tsx +283 -0
- package/dist/hooks/useTableState.ts +81 -0
- package/dist/index.ts +210 -0
- package/dist/types.ts +202 -0
- package/package.json +56 -4
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @appdirect/design-system
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AppDirect Design System components. Thin wrappers around Mantine v9.
|
|
4
|
+
|
|
5
|
+
Peer dependencies: `@mantine/core`, `@mantine/dates`, `@mantine/hooks`, `react`, and `react-dom` at the versions declared by this package.
|
|
6
|
+
|
|
7
|
+
CSS variables come from `@appdirect/ad-design-tokens`:
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import '@appdirect/ad-design-tokens/css/foundations.css';
|
|
11
|
+
import '@appdirect/ad-design-tokens/css/mantine.css';
|
|
12
|
+
import { Button, TextInput, Stack } from '@appdirect/design-system';
|
|
13
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type React from 'react';
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import { ActionIcon as MantineActionIcon, ActionIconProps as MantineActionIconProps } from '@mantine/core';
|
|
6
|
+
|
|
7
|
+
type ActionIconVariant = 'default' | 'outline' | 'link';
|
|
8
|
+
|
|
9
|
+
export interface DSActionIconProps extends Omit<MantineActionIconProps, 'variant' | 'radius'> {
|
|
10
|
+
/** Semantic variant: "default" (light blue bg), "outline" (Button default surface), or "link" (transparent) */
|
|
11
|
+
variant?: ActionIconVariant;
|
|
12
|
+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const variantMap: Record<ActionIconVariant, { variant: MantineActionIconProps['variant']; color: string }> = {
|
|
16
|
+
default: { variant: 'light', color: 'blue' },
|
|
17
|
+
outline: { variant: 'default', color: 'gray' },
|
|
18
|
+
link: { variant: 'subtle', color: 'blue' },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const ActionIcon = forwardRef<HTMLButtonElement, DSActionIconProps>(
|
|
22
|
+
({ variant = 'default', ...props }, ref) => {
|
|
23
|
+
const mapped = variantMap[variant];
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<MantineActionIcon
|
|
27
|
+
ref={ref}
|
|
28
|
+
variant={mapped.variant}
|
|
29
|
+
color={mapped.color}
|
|
30
|
+
radius="sm"
|
|
31
|
+
{...props}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
ActionIcon.displayName = 'ActionIcon';
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { Button as MantineButton, ButtonProps as MantineButtonProps } from '@mantine/core';
|
|
5
|
+
import { ComponentSize } from '../config';
|
|
6
|
+
import { type DSButtonVariant } from '../types';
|
|
7
|
+
import styles from './Button.module.css';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Enhanced Button props extending Mantine's ButtonProps
|
|
11
|
+
*/
|
|
12
|
+
export interface DSButtonProps extends Omit<MantineButtonProps, 'size' | 'color' | 'variant'> {
|
|
13
|
+
/** Button size from design system scale */
|
|
14
|
+
size?: ComponentSize;
|
|
15
|
+
/** @deprecated Color is now driven by design tokens via mantine.css adapter; this prop is ignored */
|
|
16
|
+
color?: string;
|
|
17
|
+
/** Button style variant */
|
|
18
|
+
variant?: DSButtonVariant;
|
|
19
|
+
/** Whether button takes full width */
|
|
20
|
+
fullWidth?: boolean;
|
|
21
|
+
/** Loading state with spinner */
|
|
22
|
+
loading?: boolean;
|
|
23
|
+
/** Disabled state */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** Content to display on the left side (e.g., icon, badge) */
|
|
26
|
+
leftSection?: React.ReactNode;
|
|
27
|
+
/** Content to display on the right side (e.g., icon, badge) */
|
|
28
|
+
rightSection?: React.ReactNode;
|
|
29
|
+
/** Click handler */
|
|
30
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* AppDirect Design System Button Component
|
|
35
|
+
*
|
|
36
|
+
* A enhanced button component built on top of Mantine's Button with
|
|
37
|
+
* consistent design system styling and additional functionality.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* // Basic usage
|
|
42
|
+
* <Button>Click me</Button>
|
|
43
|
+
*
|
|
44
|
+
* // Primary button with icon
|
|
45
|
+
* <Button variant="primary" leftSection={<Icon />}>
|
|
46
|
+
* Save Changes
|
|
47
|
+
* </Button>
|
|
48
|
+
*
|
|
49
|
+
* // Loading state
|
|
50
|
+
* <Button loading>Processing...</Button>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* // Different variants
|
|
56
|
+
* <Button variant="primary">Primary</Button>
|
|
57
|
+
* <Button variant="secondary">Secondary</Button>
|
|
58
|
+
* <Button variant="default">Default</Button>
|
|
59
|
+
* <Button variant="outline">Outline</Button>
|
|
60
|
+
* <Button variant="danger">Danger</Button>
|
|
61
|
+
* <Button variant="link">Link</Button>
|
|
62
|
+
* <Button variant="secret">Secret</Button>
|
|
63
|
+
* <Button variant="disabled">Disabled</Button>
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* // Sizes and colors
|
|
69
|
+
* <ADDSButton size="sm" color="primary">Small Primary</ADDSButton>
|
|
70
|
+
* <ADDSButton size="lg" color="secondary">Large Secondary</ADDSButton>
|
|
71
|
+
* <ADDSButton fullWidth>Full Width Button</ADDSButton>
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export const Button = forwardRef<HTMLButtonElement, DSButtonProps>(
|
|
75
|
+
(
|
|
76
|
+
{
|
|
77
|
+
variant = 'default',
|
|
78
|
+
size = 'sm',
|
|
79
|
+
className,
|
|
80
|
+
children,
|
|
81
|
+
leftSection,
|
|
82
|
+
rightSection,
|
|
83
|
+
...props
|
|
84
|
+
},
|
|
85
|
+
ref
|
|
86
|
+
) => {
|
|
87
|
+
// Pass our DS variant name directly — mantine.css adapter targets
|
|
88
|
+
// data-variant="primary" etc. via higher-specificity selectors.
|
|
89
|
+
// "disabled" is a state, not a Mantine variant, so map it to "default".
|
|
90
|
+
const mantineVariant = variant === 'disabled' ? 'default' : (variant ?? 'default');
|
|
91
|
+
|
|
92
|
+
// Determine if button should be disabled
|
|
93
|
+
const isDisabled = props.disabled || variant === 'disabled';
|
|
94
|
+
|
|
95
|
+
// Generate component class names
|
|
96
|
+
const componentClassName = [
|
|
97
|
+
styles.addsButton,
|
|
98
|
+
styles[`addsButton--${variant}`],
|
|
99
|
+
styles[`addsButton--${size}`],
|
|
100
|
+
leftSection && styles.hasLeftSection,
|
|
101
|
+
className,
|
|
102
|
+
]
|
|
103
|
+
.filter(Boolean)
|
|
104
|
+
.join(' ');
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<MantineButton
|
|
108
|
+
ref={ref}
|
|
109
|
+
variant={mantineVariant}
|
|
110
|
+
size={size}
|
|
111
|
+
disabled={isDisabled}
|
|
112
|
+
radius="sm"
|
|
113
|
+
className={componentClassName}
|
|
114
|
+
leftSection={leftSection}
|
|
115
|
+
rightSection={rightSection}
|
|
116
|
+
{...props}
|
|
117
|
+
>
|
|
118
|
+
{children}
|
|
119
|
+
</MantineButton>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
Button.displayName = 'Button';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { CloseButton as MantineCloseButton, CloseButtonProps } from '@mantine/core';
|
|
5
|
+
|
|
6
|
+
export interface DSCloseButtonProps extends Omit<CloseButtonProps, 'size'> {
|
|
7
|
+
/** Size of the close button */
|
|
8
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
9
|
+
/** Color variant of the close button */
|
|
10
|
+
color?: 'black' | 'blue' | 'gray';
|
|
11
|
+
/** Whether the button is disabled */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Style object for the component */
|
|
14
|
+
style?: React.CSSProperties;
|
|
15
|
+
/** Click handler */
|
|
16
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Size configurations
|
|
20
|
+
const sizeConfig = {
|
|
21
|
+
xs: {
|
|
22
|
+
size: 20,
|
|
23
|
+
iconSize: 10,
|
|
24
|
+
},
|
|
25
|
+
sm: {
|
|
26
|
+
size: 24,
|
|
27
|
+
iconSize: 12,
|
|
28
|
+
},
|
|
29
|
+
md: {
|
|
30
|
+
size: 28,
|
|
31
|
+
iconSize: 14,
|
|
32
|
+
},
|
|
33
|
+
lg: {
|
|
34
|
+
size: 32,
|
|
35
|
+
iconSize: 16,
|
|
36
|
+
},
|
|
37
|
+
xl: {
|
|
38
|
+
size: 36,
|
|
39
|
+
iconSize: 18,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const CloseButton = forwardRef<HTMLButtonElement, DSCloseButtonProps>(
|
|
44
|
+
({
|
|
45
|
+
size = 'md',
|
|
46
|
+
color = 'black',
|
|
47
|
+
disabled = false,
|
|
48
|
+
style,
|
|
49
|
+
...others
|
|
50
|
+
}, ref) => {
|
|
51
|
+
const config = sizeConfig[size];
|
|
52
|
+
|
|
53
|
+
// Define the color styling (let Mantine handle hover backgrounds)
|
|
54
|
+
const iconColor = disabled
|
|
55
|
+
? 'var(--ad-color-state-disabled-text)'
|
|
56
|
+
: color === 'blue'
|
|
57
|
+
? 'var(--ad-color-brand-primary)'
|
|
58
|
+
: color === 'gray'
|
|
59
|
+
? 'var(--ad-color-text-dimmed)'
|
|
60
|
+
: 'var(--ad-color-text-default)';
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<MantineCloseButton
|
|
64
|
+
ref={ref}
|
|
65
|
+
variant="subtle"
|
|
66
|
+
size={config.size}
|
|
67
|
+
disabled={disabled}
|
|
68
|
+
style={{
|
|
69
|
+
color: iconColor,
|
|
70
|
+
borderRadius: 'var(--mantine-radius-sm)',
|
|
71
|
+
minWidth: config.size,
|
|
72
|
+
minHeight: config.size,
|
|
73
|
+
width: config.size,
|
|
74
|
+
height: config.size,
|
|
75
|
+
...style,
|
|
76
|
+
}}
|
|
77
|
+
{...others}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
CloseButton.displayName = 'CloseButton';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Buttons AppDirect Design System Components
|
|
3
|
+
*
|
|
4
|
+
* This module exports all button-related components from the design system.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { Button } from './Button';
|
|
8
|
+
export type { DSButtonProps } from './Button';
|
|
9
|
+
|
|
10
|
+
export { ActionIcon } from './ActionIcon';
|
|
11
|
+
export type { DSActionIconProps } from './ActionIcon';
|
|
12
|
+
|
|
13
|
+
export { CloseButton } from './CloseButton';
|
|
14
|
+
export type { DSCloseButtonProps } from './CloseButton';
|
|
15
|
+
|
|
16
|
+
// Future button component exports will go here:
|
|
17
|
+
// export { ADDSActionIcon } from './ActionIcon';
|
|
18
|
+
// export { ADDSCloseButton } from './CloseButton';
|
|
19
|
+
// export type { ADDSActionIconProps } from './ActionIcon';
|
|
20
|
+
// export type { ADDSCloseButtonProps } from './CloseButton';
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { CloseButton, Combobox, TextInput, useCombobox } from '@mantine/core';
|
|
5
|
+
|
|
6
|
+
const countries = [
|
|
7
|
+
'United States',
|
|
8
|
+
'Canada',
|
|
9
|
+
'United Kingdom',
|
|
10
|
+
'Germany',
|
|
11
|
+
'France',
|
|
12
|
+
'Australia',
|
|
13
|
+
'Japan',
|
|
14
|
+
'Singapore',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export interface DSAutocompleteClearableProps {
|
|
18
|
+
/** Label for the input */
|
|
19
|
+
label?: string;
|
|
20
|
+
/** Placeholder text */
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
/** Data array for options - can be strings or objects with value/label */
|
|
23
|
+
data?: string[] | { value: string; label: string }[];
|
|
24
|
+
/** Description text displayed below the input */
|
|
25
|
+
description?: string;
|
|
26
|
+
/** Error message */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** Whether the field is required */
|
|
29
|
+
required?: boolean;
|
|
30
|
+
/** Whether to show "(optional)" next to the label */
|
|
31
|
+
showOptional?: boolean;
|
|
32
|
+
/** Whether the input is disabled */
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/** Input size */
|
|
35
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
36
|
+
/** Style object for the component */
|
|
37
|
+
style?: React.CSSProperties;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function AutocompleteClearable({
|
|
41
|
+
label,
|
|
42
|
+
placeholder = "Pick a country or type anything",
|
|
43
|
+
data = countries,
|
|
44
|
+
description,
|
|
45
|
+
error,
|
|
46
|
+
required = false,
|
|
47
|
+
showOptional = false,
|
|
48
|
+
disabled = false,
|
|
49
|
+
size = 'md',
|
|
50
|
+
style,
|
|
51
|
+
...props
|
|
52
|
+
}: DSAutocompleteClearableProps) {
|
|
53
|
+
const combobox = useCombobox();
|
|
54
|
+
const [value, setValue] = useState('');
|
|
55
|
+
|
|
56
|
+
// Convert data to consistent format
|
|
57
|
+
const normalizedData = data.map(item =>
|
|
58
|
+
typeof item === 'string' ? { value: item, label: item } : item
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const shouldFilterOptions = !normalizedData.some((item) => item.value === value);
|
|
62
|
+
const filteredOptions = shouldFilterOptions
|
|
63
|
+
? normalizedData.filter((item) =>
|
|
64
|
+
item.label.toLowerCase().includes(value.toLowerCase().trim()) ||
|
|
65
|
+
item.value.toLowerCase().includes(value.toLowerCase().trim())
|
|
66
|
+
)
|
|
67
|
+
: normalizedData;
|
|
68
|
+
|
|
69
|
+
const options = filteredOptions.map((item) => (
|
|
70
|
+
<Combobox.Option value={item.value} key={item.value}>
|
|
71
|
+
{item.label}
|
|
72
|
+
</Combobox.Option>
|
|
73
|
+
));
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div style={style}>
|
|
77
|
+
<Combobox
|
|
78
|
+
onOptionSubmit={(optionValue) => {
|
|
79
|
+
setValue(optionValue);
|
|
80
|
+
combobox.closeDropdown();
|
|
81
|
+
}}
|
|
82
|
+
store={combobox}
|
|
83
|
+
withinPortal={false}
|
|
84
|
+
>
|
|
85
|
+
<Combobox.Target>
|
|
86
|
+
<TextInput
|
|
87
|
+
label={label}
|
|
88
|
+
description={description}
|
|
89
|
+
error={error}
|
|
90
|
+
required={required}
|
|
91
|
+
size={size}
|
|
92
|
+
disabled={disabled}
|
|
93
|
+
placeholder={placeholder}
|
|
94
|
+
value={value}
|
|
95
|
+
onChange={(event) => {
|
|
96
|
+
setValue(event.currentTarget.value);
|
|
97
|
+
combobox.openDropdown();
|
|
98
|
+
combobox.updateSelectedOptionIndex();
|
|
99
|
+
}}
|
|
100
|
+
onClick={() => combobox.openDropdown()}
|
|
101
|
+
onFocus={() => combobox.openDropdown()}
|
|
102
|
+
onBlur={() => combobox.closeDropdown()}
|
|
103
|
+
withAsterisk={required && !showOptional}
|
|
104
|
+
{...(showOptional && !required && {
|
|
105
|
+
label: label ? `${label} (optional)` : undefined
|
|
106
|
+
})}
|
|
107
|
+
rightSection={
|
|
108
|
+
value !== '' && !disabled && (
|
|
109
|
+
<CloseButton
|
|
110
|
+
size="sm"
|
|
111
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
112
|
+
onClick={() => setValue('')}
|
|
113
|
+
aria-label="Clear value"
|
|
114
|
+
/>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
/>
|
|
118
|
+
</Combobox.Target>
|
|
119
|
+
|
|
120
|
+
<Combobox.Dropdown>
|
|
121
|
+
<Combobox.Options>
|
|
122
|
+
{options.length === 0 ? <Combobox.Empty>Nothing found</Combobox.Empty> : options}
|
|
123
|
+
</Combobox.Options>
|
|
124
|
+
</Combobox.Dropdown>
|
|
125
|
+
</Combobox>
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { Select, DSSelectProps } from './Select';
|
|
5
|
+
|
|
6
|
+
// ========================== TYPES ==========================
|
|
7
|
+
|
|
8
|
+
export interface DSComboboxProps extends DSSelectProps {}
|
|
9
|
+
|
|
10
|
+
// ========================== COMPONENT ==========================
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* AppDirect Design System Combobox Component
|
|
14
|
+
*
|
|
15
|
+
* Identical to Select — a single-selection dropdown built on Mantine's Select
|
|
16
|
+
* with DS defaults (radius, IconSelector, label enhancements). This component
|
|
17
|
+
* exists as a separate identity for Figma Code Connect, where the Combobox
|
|
18
|
+
* Figma component maps to this wrapper.
|
|
19
|
+
*
|
|
20
|
+
* For basic single-select use cases, use either Select or Combobox.
|
|
21
|
+
* For advanced use cases, use SearchableSelect or build on Mantine's
|
|
22
|
+
* Combobox primitives directly.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* <Combobox
|
|
27
|
+
* data={['Option 1', 'Option 2', 'Option 3']}
|
|
28
|
+
* placeholder="Select option"
|
|
29
|
+
* label="Choose an option"
|
|
30
|
+
* />
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const Combobox = forwardRef<HTMLInputElement, DSComboboxProps>(
|
|
34
|
+
(props, ref) => <Select ref={ref} {...props} />
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
Combobox.displayName = 'Combobox';
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Checkbox, Combobox,Input, Pill as MantinePill, PillsInput, useCombobox, InputWrapper } from '@mantine/core';
|
|
5
|
+
import { Inline } from '..';
|
|
6
|
+
import { Pill } from '../DataDisplay/Pill';
|
|
7
|
+
|
|
8
|
+
const technologies = ['React', 'Vue', 'Angular', 'Node.js', 'Docker', 'Kubernetes', 'AWS', 'MongoDB'];
|
|
9
|
+
|
|
10
|
+
const MAX_DISPLAYED_VALUES = 2;
|
|
11
|
+
|
|
12
|
+
export interface DSMultiselectProps {
|
|
13
|
+
/** Label for the input */
|
|
14
|
+
label?: string;
|
|
15
|
+
/** Placeholder text */
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
/** Data array for options - can be strings or objects with value/label */
|
|
18
|
+
data?: string[] | { value: string; label: string }[];
|
|
19
|
+
/** Description text displayed below the input */
|
|
20
|
+
description?: string;
|
|
21
|
+
/** Error message */
|
|
22
|
+
error?: string;
|
|
23
|
+
/** Whether the field is required */
|
|
24
|
+
required?: boolean;
|
|
25
|
+
/** Whether to show "(optional)" next to the label */
|
|
26
|
+
showOptional?: boolean;
|
|
27
|
+
/** Whether the input is disabled */
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/** Whether the select is searchable */
|
|
30
|
+
searchable?: boolean;
|
|
31
|
+
/** Input size */
|
|
32
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
33
|
+
/** Style object for the component */
|
|
34
|
+
style?: React.CSSProperties;
|
|
35
|
+
/** Maximum number of pills to display before showing "+X more" */
|
|
36
|
+
maxDisplayedValues?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function Multiselect({
|
|
40
|
+
label,
|
|
41
|
+
placeholder = "Pick one or more technologies",
|
|
42
|
+
data = technologies,
|
|
43
|
+
description,
|
|
44
|
+
error,
|
|
45
|
+
required = false,
|
|
46
|
+
showOptional = false,
|
|
47
|
+
disabled = false,
|
|
48
|
+
searchable = true,
|
|
49
|
+
size = 'md',
|
|
50
|
+
style,
|
|
51
|
+
maxDisplayedValues = MAX_DISPLAYED_VALUES,
|
|
52
|
+
...props
|
|
53
|
+
}: DSMultiselectProps) {
|
|
54
|
+
const combobox = useCombobox({
|
|
55
|
+
onDropdownClose: () => combobox.resetSelectedOption(),
|
|
56
|
+
onDropdownOpen: () => combobox.updateSelectedOptionIndex('active'),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const [value, setValue] = useState<string[]>([]);
|
|
60
|
+
|
|
61
|
+
const handleValueSelect = (val: string) =>
|
|
62
|
+
setValue((current) =>
|
|
63
|
+
current.includes(val) ? current.filter((v) => v !== val) : [...current, val]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const handleValueRemove = (val: string) =>
|
|
67
|
+
setValue((current) => current.filter((v) => v !== val));
|
|
68
|
+
|
|
69
|
+
const values = value
|
|
70
|
+
.slice(
|
|
71
|
+
0,
|
|
72
|
+
maxDisplayedValues === value.length ? maxDisplayedValues : maxDisplayedValues - 1
|
|
73
|
+
)
|
|
74
|
+
.map((item) => (
|
|
75
|
+
<Pill key={item} withRemoveButton onRemove={() => handleValueRemove(item)} size={size}>
|
|
76
|
+
{item}
|
|
77
|
+
</Pill>
|
|
78
|
+
));
|
|
79
|
+
|
|
80
|
+
// Convert data to consistent format
|
|
81
|
+
const normalizedData = data.map(item =>
|
|
82
|
+
typeof item === 'string' ? { value: item, label: item } : item
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const options = normalizedData.map((item) => (
|
|
86
|
+
<Combobox.Option value={item.value} key={item.value} active={value.includes(item.value)}>
|
|
87
|
+
<Inline gap="sm">
|
|
88
|
+
<Checkbox
|
|
89
|
+
checked={value.includes(item.value)}
|
|
90
|
+
onChange={() => {}} // Handled by onOptionSubmit
|
|
91
|
+
aria-hidden
|
|
92
|
+
tabIndex={-1}
|
|
93
|
+
style={{ pointerEvents: 'none' }}
|
|
94
|
+
/>
|
|
95
|
+
<span>{item.label}</span>
|
|
96
|
+
</Inline>
|
|
97
|
+
</Combobox.Option>
|
|
98
|
+
));
|
|
99
|
+
|
|
100
|
+
// Determine the display label
|
|
101
|
+
const displayLabel = showOptional && !required && label ? `${label} (optional)` : label;
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div style={style}>
|
|
105
|
+
<InputWrapper
|
|
106
|
+
label={displayLabel}
|
|
107
|
+
description={description}
|
|
108
|
+
error={error}
|
|
109
|
+
required={required && !showOptional}
|
|
110
|
+
size={size}
|
|
111
|
+
withAsterisk={required && !showOptional}
|
|
112
|
+
>
|
|
113
|
+
<Combobox store={combobox} onOptionSubmit={handleValueSelect} withinPortal={false} disabled={disabled}>
|
|
114
|
+
<Combobox.DropdownTarget>
|
|
115
|
+
<PillsInput
|
|
116
|
+
pointer
|
|
117
|
+
onClick={() => !disabled && combobox.toggleDropdown()}
|
|
118
|
+
size={size}
|
|
119
|
+
disabled={disabled}
|
|
120
|
+
error={!!error}
|
|
121
|
+
>
|
|
122
|
+
<MantinePill.Group>
|
|
123
|
+
{value.length > 0 ? (
|
|
124
|
+
<>
|
|
125
|
+
{values}
|
|
126
|
+
{value.length > maxDisplayedValues && (
|
|
127
|
+
<Pill size={size}>+{value.length - (maxDisplayedValues - 1)} more</Pill>
|
|
128
|
+
)}
|
|
129
|
+
</>
|
|
130
|
+
) : (
|
|
131
|
+
<Input.Placeholder>{placeholder}</Input.Placeholder>
|
|
132
|
+
)}
|
|
133
|
+
|
|
134
|
+
<Combobox.EventsTarget>
|
|
135
|
+
<PillsInput.Field
|
|
136
|
+
type="hidden"
|
|
137
|
+
onBlur={() => combobox.closeDropdown()}
|
|
138
|
+
onKeyDown={(event) => {
|
|
139
|
+
if (event.key === 'Backspace' && !disabled) {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
handleValueRemove(value[value.length - 1]);
|
|
142
|
+
}
|
|
143
|
+
}}
|
|
144
|
+
disabled={disabled}
|
|
145
|
+
/>
|
|
146
|
+
</Combobox.EventsTarget>
|
|
147
|
+
</MantinePill.Group>
|
|
148
|
+
</PillsInput>
|
|
149
|
+
</Combobox.DropdownTarget>
|
|
150
|
+
|
|
151
|
+
<Combobox.Dropdown>
|
|
152
|
+
<Combobox.Options>{options}</Combobox.Options>
|
|
153
|
+
</Combobox.Dropdown>
|
|
154
|
+
</Combobox>
|
|
155
|
+
</InputWrapper>
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
}
|