@hyphen/hyphen-components 7.3.1 → 7.3.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/css/utilities.css +1 -1
- package/dist/css/variables.css +18 -28
- package/dist/hyphen-components.cjs.development.js +5718 -5018
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +18 -2
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +5619 -4843
- package/dist/hyphen-components.esm.js.map +1 -1
- package/dist/index.d.ts +2693 -57
- package/dist/index.js +0 -1
- package/package.json +18 -19
- package/src/components/Badge/Badge.module.scss +6 -0
- package/src/components/Badge/Badge.stories.tsx +1 -0
- package/src/components/Badge/Badge.test.tsx +3 -2
- package/src/components/Badge/Badge.tsx +5 -3
- package/src/components/Box/Box.tsx +5 -2
- package/src/components/Button/Button.module.scss +1 -1
- package/src/components/Button/Button.test.tsx +2 -2
- package/src/components/Calendar/Calendar.test.tsx +262 -0
- package/src/components/Card/Card.tsx +2 -0
- package/src/components/CheckboxInput/components/Checkbox.module.scss +1 -1
- package/src/components/CheckboxInput/components/Checkbox.tsx +2 -0
- package/src/components/Details/Details.module.scss +2 -2
- package/src/components/Details/Details.tsx +2 -0
- package/src/components/Drawer/Drawer.stories.tsx +1 -1
- package/src/components/Drawer/Drawer.test.tsx +494 -56
- package/src/components/Drawer/Drawer.tsx +7 -1
- package/src/components/DropdownMenu/DropdownMenu.test.tsx +532 -12
- package/src/components/FormControl/FormControl.tsx +2 -0
- package/src/components/Formik/Formik.stories.tsx +30 -7
- package/src/components/Formik/FormikSelectInput/FormikSelectInput.tsx +6 -5
- package/src/components/Formik/FormikToggleGroup/FormikToggleGroup.tsx +1 -1
- package/src/components/HelpText/HelpText.tsx +2 -0
- package/src/components/Icon/Icon.stories.tsx +1 -1
- package/src/components/Icon/Icon.tsx +2 -0
- package/src/components/Modal/Modal.test.tsx +630 -81
- package/src/components/Modal/Modal.tsx +2 -0
- package/src/components/Modal/components/ModalFooter/ModalFooter.test.tsx +2 -2
- package/src/components/Popover/Popover.tsx +2 -0
- package/src/components/RadioGroup/RadioInput/RadioInput.tsx +2 -0
- package/src/components/SelectInput/SelectInput.stories.tsx +22 -22
- package/src/components/SelectInput/SelectInput.tsx +13 -9
- package/src/components/SelectInputInset/SelectInputInset.tsx +2 -0
- package/src/components/Sidebar/Sidebar.module.scss +4 -0
- package/src/components/Sidebar/Sidebar.stories.tsx +8 -4
- package/src/components/Sidebar/Sidebar.test.tsx +7 -4
- package/src/components/Sidebar/Sidebar.tsx +21 -12
- package/src/components/Table/Table.stories.tsx +102 -52
- package/src/components/TextInput/TextInput.tsx +2 -0
- package/src/components/TextInputInset/TextInputInset.tsx +2 -0
- package/src/components/TextareaInputInset/TextareaInputInset.tsx +2 -0
- package/src/components/TimePickerNative/TimePickerNative.stories.tsx +0 -1
- package/src/components/Toast/Toast.store.ts +1 -1
- package/src/components/Toast/Toast.stories.tsx +3 -2
- package/src/components/Toast/Toast.test.tsx +8 -6
- package/src/components/Toggle/Toggle.tsx +2 -0
- package/src/components/ToggleGroup/ToggleGroup.tsx +2 -0
- package/src/docs/Colors.mdx +0 -13
- package/src/lib/getColumnKeys.ts +3 -3
- package/src/lib/mergeRefs.ts +1 -1
- package/src/lib/tokens.ts +4 -4
- package/dist/components/Alert/Alert.constants.d.ts +0 -8
- package/dist/components/Alert/Alert.d.ts +0 -42
- package/dist/components/Alert/Alert.stories.d.ts +0 -12
- package/dist/components/Alert/Alert.types.d.ts +0 -7
- package/dist/components/AspectRatio/AspectRatio.d.ts +0 -3
- package/dist/components/AspectRatio/AspectRatio.stories.d.ts +0 -6
- package/dist/components/Badge/Badge.d.ts +0 -24
- package/dist/components/Badge/Badge.stories.d.ts +0 -8
- package/dist/components/Box/Box.d.ts +0 -247
- package/dist/components/Box/Box.stories.d.ts +0 -46
- package/dist/components/Button/Button.constants.d.ts +0 -3
- package/dist/components/Button/Button.d.ts +0 -53
- package/dist/components/Button/Button.stories.d.ts +0 -16
- package/dist/components/Calendar/Calendar.d.ts +0 -7
- package/dist/components/Calendar/Calendar.stories.d.ts +0 -12
- package/dist/components/Card/Card.d.ts +0 -17
- package/dist/components/Card/Card.stories.d.ts +0 -8
- package/dist/components/Card/components/CardFooter/CardFooter.d.ts +0 -13
- package/dist/components/Card/components/CardHeader/CardHeader.d.ts +0 -13
- package/dist/components/Card/components/CardSection/CardSection.d.ts +0 -46
- package/dist/components/Card/components/index.d.ts +0 -3
- package/dist/components/CheckboxInput/CheckboxInput.d.ts +0 -72
- package/dist/components/CheckboxInput/CheckboxInput.stories.d.ts +0 -18
- package/dist/components/CheckboxInput/components/Checkbox.d.ts +0 -71
- package/dist/components/CheckboxInput/components/CheckboxIcon.d.ts +0 -27
- package/dist/components/Collapsible/Collapsible.d.ts +0 -5
- package/dist/components/Collapsible/Collapsible.stories.d.ts +0 -9
- package/dist/components/Details/Details.d.ts +0 -15
- package/dist/components/Details/Details.stories.d.ts +0 -6
- package/dist/components/Details/DetailsSummary.d.ts +0 -7
- package/dist/components/Drawer/Drawer.d.ts +0 -105
- package/dist/components/Drawer/Drawer.stories.d.ts +0 -62
- package/dist/components/DropdownMenu/DropdownMenu.d.ts +0 -25
- package/dist/components/DropdownMenu/DropdownMenu.stories.d.ts +0 -9
- package/dist/components/FormControl/FormControl.d.ts +0 -38
- package/dist/components/FormLabel/FormLabel.d.ts +0 -41
- package/dist/components/FormLabel/FormLabel.stories.d.ts +0 -6
- package/dist/components/Formik/Formik.stories.d.ts +0 -18
- package/dist/components/Formik/FormikCheckboxInput/FormikCheckboxInput.d.ts +0 -12
- package/dist/components/Formik/FormikRadioGroup/FormikRadioGroup.d.ts +0 -12
- package/dist/components/Formik/FormikSelectInput/FormikSelectInput.d.ts +0 -13
- package/dist/components/Formik/FormikSelectInputInset/FormikSelectInputInset.d.ts +0 -12
- package/dist/components/Formik/FormikSelectInputNative/FormikSelectInputNative.d.ts +0 -12
- package/dist/components/Formik/FormikSwitch/FormikSwitch.d.ts +0 -12
- package/dist/components/Formik/FormikTextInput/FormikTextInput.d.ts +0 -12
- package/dist/components/Formik/FormikTextInputInset/FormikTextInputInset.d.ts +0 -12
- package/dist/components/Formik/FormikTextareaInput/FormikTextareaInput.d.ts +0 -12
- package/dist/components/Formik/FormikTextareaInputInset/FormikTextareaInputInset.d.ts +0 -12
- package/dist/components/Formik/FormikTimePicker/FormikTimePicker.d.ts +0 -12
- package/dist/components/Formik/FormikTimePickerNative/FormikTimePickerNative.d.ts +0 -12
- package/dist/components/Formik/FormikToggleGroup/FormikToggleGroup.d.ts +0 -20
- package/dist/components/Formik/FormikToggleGroupMulti/FormikToggleGroupMulti.d.ts +0 -18
- package/dist/components/Heading/Heading.constants.d.ts +0 -10
- package/dist/components/Heading/Heading.d.ts +0 -35
- package/dist/components/Heading/Heading.stories.d.ts +0 -9
- package/dist/components/HelpText/HelpText.d.ts +0 -12
- package/dist/components/Icon/Icon.d.ts +0 -22
- package/dist/components/Icon/Icon.stories.d.ts +0 -10
- package/dist/components/InputValidationMessage/InputValidationMessage.d.ts +0 -9
- package/dist/components/Modal/Modal.d.ts +0 -83
- package/dist/components/Modal/Modal.stories.d.ts +0 -13
- package/dist/components/Modal/components/ModalBody/ModalBody.d.ts +0 -4
- package/dist/components/Modal/components/ModalFooter/ModalFooter.d.ts +0 -4
- package/dist/components/Modal/components/ModalHeader/ModalHeader.d.ts +0 -21
- package/dist/components/Modal/components/index.d.ts +0 -4
- package/dist/components/Pagination/Pagination.d.ts +0 -51
- package/dist/components/Pagination/Pagination.stories.d.ts +0 -8
- package/dist/components/Pagination/Pagination.utilities.d.ts +0 -10
- package/dist/components/Popover/Popover.d.ts +0 -8
- package/dist/components/Popover/Popover.stories.d.ts +0 -7
- package/dist/components/RadioGroup/RadioGroup.d.ts +0 -75
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts +0 -16
- package/dist/components/RadioGroup/RadioInput/RadioInput.d.ts +0 -57
- package/dist/components/RadioGroup/RadioInput/RadioInputIcon.d.ts +0 -27
- package/dist/components/RangeInput/RangeInput.d.ts +0 -29
- package/dist/components/RangeInput/RangeInput.stories.d.ts +0 -7
- package/dist/components/ResponsiveProvider/ResponsiveProvider.d.ts +0 -17
- package/dist/components/ResponsiveProvider/ResponsiveProvider.stories.d.ts +0 -7
- package/dist/components/SelectInput/SelectInput.d.ts +0 -148
- package/dist/components/SelectInput/SelectInput.stories.d.ts +0 -24
- package/dist/components/SelectInputInset/SelectInputInset.d.ts +0 -92
- package/dist/components/SelectInputInset/SelectInputInset.stories.d.ts +0 -12
- package/dist/components/SelectInputNative/SelectInputNative.d.ts +0 -45
- package/dist/components/SelectInputNative/SelectInputNative.stories.d.ts +0 -19
- package/dist/components/Sidebar/Sidebar.d.ts +0 -57
- package/dist/components/Sidebar/Sidebar.stories.d.ts +0 -9
- package/dist/components/Spinner/Spinner.d.ts +0 -12
- package/dist/components/Spinner/Spinner.stories.d.ts +0 -8
- package/dist/components/Switch/Switch.d.ts +0 -64
- package/dist/components/Switch/Switch.stories.d.ts +0 -12
- package/dist/components/Table/Table.d.ts +0 -86
- package/dist/components/Table/Table.stories.d.ts +0 -31
- package/dist/components/Table/TableBody/TableBody.d.ts +0 -52
- package/dist/components/Table/TableBody/TableBodyCell/TableBodyCell.d.ts +0 -45
- package/dist/components/Table/TableHead/TableHead.d.ts +0 -46
- package/dist/components/Table/TableHead/TableHeaderCell/TableHeaderCell.d.ts +0 -65
- package/dist/components/Table/common/TableRow/TableRow.d.ts +0 -67
- package/dist/components/TextInput/TextInput.d.ts +0 -106
- package/dist/components/TextInput/TextInput.stories.d.ts +0 -19
- package/dist/components/TextInputInset/TextInputInset.d.ts +0 -102
- package/dist/components/TextInputInset/TextInputInset.stories.d.ts +0 -13
- package/dist/components/TextareaInput/TextareaInput.d.ts +0 -97
- package/dist/components/TextareaInput/TextareaInput.stories.d.ts +0 -23
- package/dist/components/TextareaInputInset/TextareaInputInset.d.ts +0 -105
- package/dist/components/TextareaInputInset/TextareaInputInset.stories.d.ts +0 -12
- package/dist/components/ThemeProvider/ThemeProvider.d.ts +0 -15
- package/dist/components/ThemeProvider/ThemeProvider.stories.d.ts +0 -6
- package/dist/components/TimePicker/TimePicker.d.ts +0 -35
- package/dist/components/TimePicker/TimePicker.stories.d.ts +0 -12
- package/dist/components/TimePickerNative/TimePickerNative.d.ts +0 -39
- package/dist/components/TimePickerNative/TimePickerNative.stories.d.ts +0 -11
- package/dist/components/Toast/Toast.store.d.ts +0 -36
- package/dist/components/Toast/Toast.stories.d.ts +0 -14
- package/dist/components/Toast/Toast.types.d.ts +0 -75
- package/dist/components/Toast/ToastContainer.d.ts +0 -43
- package/dist/components/Toast/ToastNotification.d.ts +0 -28
- package/dist/components/Toast/index.d.ts +0 -4
- package/dist/components/Toast/toast.d.ts +0 -20
- package/dist/components/Toast/useToasts.d.ts +0 -14
- package/dist/components/Toggle/Toggle.d.ts +0 -7
- package/dist/components/Toggle/Toggle.stories.d.ts +0 -11
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +0 -19
- package/dist/components/ToggleGroup/ToggleGroup.stories.d.ts +0 -12
- package/dist/components/Tooltip/Tooltip.d.ts +0 -8
- package/dist/components/Tooltip/Tooltip.stories.d.ts +0 -8
- package/dist/constants/keyCodes.d.ts +0 -2
- package/dist/css/index.css +0 -36
- package/dist/hooks/index.d.ts +0 -6
- package/dist/hooks/useBreakpoint/useBreakpoint.d.ts +0 -9
- package/dist/hooks/useBreakpoint/useBreakpoint.stories.d.ts +0 -6
- package/dist/hooks/useIsMobile/useIsMobile.d.ts +0 -1
- package/dist/hooks/useIsMobile/useIsMobile.stories.d.ts +0 -6
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +0 -2
- package/dist/hooks/useOpenClose/useOpenClose.d.ts +0 -39
- package/dist/hooks/useOpenClose/useOpenClose.stories.d.ts +0 -6
- package/dist/hooks/useTheme/useTheme.d.ts +0 -5
- package/dist/hooks/useTheme/useTheme.stories.d.ts +0 -6
- package/dist/hooks/useWindowSize/useWindowSize.d.ts +0 -7
- package/dist/hooks/useWindowSize/useWindowSize.stories.d.ts +0 -6
- package/dist/lib/cssShorthandToClasses.d.ts +0 -4
- package/dist/lib/doesStringIncludeCssUnit.d.ts +0 -1
- package/dist/lib/generateResponsiveClasses.d.ts +0 -2
- package/dist/lib/getAutoCompleteValue.d.ts +0 -1
- package/dist/lib/getColumnKeys.d.ts +0 -3
- package/dist/lib/getDimensionCss.d.ts +0 -12
- package/dist/lib/getElementType.d.ts +0 -14
- package/dist/lib/getFlexCss.d.ts +0 -9
- package/dist/lib/index.d.ts +0 -15
- package/dist/lib/isFunction.d.ts +0 -3
- package/dist/lib/mergeRefs.d.ts +0 -2
- package/dist/lib/prefersReducedMotion.d.ts +0 -1
- package/dist/lib/react-children-utilities/filter.d.ts +0 -3
- package/dist/lib/react-children-utilities/index.d.ts +0 -1
- package/dist/lib/reactRouterClickHandler.d.ts +0 -12
- package/dist/lib/resolveValue.d.ts +0 -3
- package/dist/lib/tokens.d.ts +0 -22
- package/dist/modes.d.ts +0 -8
- package/dist/types/index.d.ts +0 -103
- package/dist/types/lib.types.d.ts +0 -3
|
@@ -3,7 +3,12 @@ import React, { useEffect, useState } from 'react';
|
|
|
3
3
|
import { Table } from './Table';
|
|
4
4
|
import { Button } from '../Button/Button';
|
|
5
5
|
import { Badge } from '../Badge/Badge';
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
Column as ColumnType,
|
|
8
|
+
Cell,
|
|
9
|
+
Row,
|
|
10
|
+
EventWithColumnKey,
|
|
11
|
+
} from '../../types';
|
|
7
12
|
|
|
8
13
|
const meta: Meta<typeof Table> = {
|
|
9
14
|
title: 'Components/Table',
|
|
@@ -12,6 +17,13 @@ const meta: Meta<typeof Table> = {
|
|
|
12
17
|
|
|
13
18
|
export default meta;
|
|
14
19
|
|
|
20
|
+
type SortDirection = 'ascending' | 'descending';
|
|
21
|
+
type SortedColumn = {
|
|
22
|
+
dataKey?: string;
|
|
23
|
+
sortDirection?: SortDirection;
|
|
24
|
+
};
|
|
25
|
+
type SortableRow = Record<string, string | number>;
|
|
26
|
+
|
|
15
27
|
export const Column = () =>
|
|
16
28
|
(() => {
|
|
17
29
|
const codePreviewStyle = {
|
|
@@ -94,7 +106,7 @@ export const Column = () =>
|
|
|
94
106
|
{
|
|
95
107
|
heading: 'Type',
|
|
96
108
|
dataKey: 'type',
|
|
97
|
-
render: (cell:
|
|
109
|
+
render: (cell: string) => <code style={codePreviewStyle}>{cell}</code>,
|
|
98
110
|
},
|
|
99
111
|
{ heading: 'Description', dataKey: 'description' },
|
|
100
112
|
];
|
|
@@ -109,12 +121,15 @@ export const CommonExample = () =>
|
|
|
109
121
|
{
|
|
110
122
|
heading: 'Customer',
|
|
111
123
|
dataKey: 'customerInfo',
|
|
112
|
-
render: (_cell
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
<div
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
render: (_cell?: Cell, row?: Row) => {
|
|
125
|
+
const customerRow = row as { name?: string; email?: string } | undefined;
|
|
126
|
+
return (
|
|
127
|
+
<div>
|
|
128
|
+
<div>{customerRow?.name}</div>
|
|
129
|
+
<div className="font-color-base">{customerRow?.email}</div>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
},
|
|
118
133
|
},
|
|
119
134
|
{ heading: 'Phone', dataKey: 'phone', width: 125 },
|
|
120
135
|
{ heading: 'Plan', dataKey: 'plan', width: 125 },
|
|
@@ -164,31 +179,37 @@ export const Loading = () =>
|
|
|
164
179
|
})();
|
|
165
180
|
|
|
166
181
|
export const Sortable = () => {
|
|
167
|
-
|
|
168
|
-
const sortDescending = (arrOfObj, key) =>
|
|
182
|
+
const sortDescending = (arrOfObj: SortableRow[], key: string) =>
|
|
169
183
|
[...arrOfObj].sort((a, b) => (b[key] > a[key] ? 1 : -1));
|
|
170
|
-
|
|
171
|
-
const sortAscending = (arrOfObj, key) =>
|
|
184
|
+
const sortAscending = (arrOfObj: SortableRow[], key: string) =>
|
|
172
185
|
[...arrOfObj].sort((a, b) => (a[key] > b[key] ? 1 : -1));
|
|
173
|
-
const getNewSortDirection = (
|
|
186
|
+
const getNewSortDirection = (
|
|
187
|
+
sortedKey: string,
|
|
188
|
+
currentSortedColumn: SortedColumn
|
|
189
|
+
) => {
|
|
174
190
|
if (
|
|
175
|
-
|
|
191
|
+
sortedKey === currentSortedColumn.dataKey &&
|
|
176
192
|
currentSortedColumn.sortDirection === 'ascending'
|
|
177
193
|
)
|
|
178
194
|
return 'descending';
|
|
179
195
|
return 'ascending';
|
|
180
196
|
};
|
|
181
|
-
const initialData = [
|
|
197
|
+
const initialData: SortableRow[] = [
|
|
182
198
|
{ id: 1, color: 'red', flavor: 'vanilla' },
|
|
183
199
|
{ id: 2, color: 'green', flavor: 'strawberry' },
|
|
184
200
|
{ id: 3, color: 'blue', flavor: 'chocolate' },
|
|
185
201
|
];
|
|
186
|
-
const [sortedColumn, setSortedColumn] = useState<
|
|
187
|
-
const [tableData, setTableData] = useState(initialData);
|
|
188
|
-
const handleSort = (event:
|
|
189
|
-
const
|
|
202
|
+
const [sortedColumn, setSortedColumn] = useState<SortedColumn>({});
|
|
203
|
+
const [tableData, setTableData] = useState<SortableRow[]>(initialData);
|
|
204
|
+
const handleSort = (event: EventWithColumnKey) => {
|
|
205
|
+
const sortedKey =
|
|
206
|
+
typeof event.sortedKey === 'string' ? event.sortedKey : undefined;
|
|
207
|
+
if (!sortedKey) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const newSortDirection = getNewSortDirection(sortedKey, sortedColumn);
|
|
190
211
|
setSortedColumn({
|
|
191
|
-
dataKey:
|
|
212
|
+
dataKey: sortedKey,
|
|
192
213
|
sortDirection: newSortDirection,
|
|
193
214
|
});
|
|
194
215
|
};
|
|
@@ -218,38 +239,45 @@ export const Sortable = () => {
|
|
|
218
239
|
};
|
|
219
240
|
|
|
220
241
|
export const SortablewithDefaultSortedColumn = () => {
|
|
221
|
-
|
|
222
|
-
const sortDescending = (arrOfObj, key) =>
|
|
242
|
+
const sortDescending = (arrOfObj: SortableRow[], key: string) =>
|
|
223
243
|
[...arrOfObj].sort((a, b) => (b[key] > a[key] ? 1 : -1));
|
|
224
|
-
|
|
225
|
-
const sortAscending = (arrOfObj, key) =>
|
|
244
|
+
const sortAscending = (arrOfObj: SortableRow[], key: string) =>
|
|
226
245
|
[...arrOfObj].sort((a, b) => (a[key] > b[key] ? 1 : -1));
|
|
227
|
-
const getNewSortDirection = (
|
|
246
|
+
const getNewSortDirection = (
|
|
247
|
+
sortedKey: string,
|
|
248
|
+
currentSortedColumn: SortedColumn
|
|
249
|
+
) => {
|
|
228
250
|
if (
|
|
229
|
-
|
|
251
|
+
sortedKey === currentSortedColumn.dataKey &&
|
|
230
252
|
currentSortedColumn.sortDirection === 'ascending'
|
|
231
253
|
)
|
|
232
254
|
return 'descending';
|
|
233
255
|
return 'ascending';
|
|
234
256
|
};
|
|
235
|
-
const initialData = [
|
|
257
|
+
const initialData: SortableRow[] = [
|
|
236
258
|
{ id: 1, color: 'red', flavor: 'vanilla' },
|
|
237
259
|
{ id: 2, color: 'green', flavor: 'strawberry' },
|
|
238
260
|
{ id: 3, color: 'blue', flavor: 'chocolate' },
|
|
239
261
|
];
|
|
240
|
-
const [sortedColumn, setSortedColumn] = useState<
|
|
262
|
+
const [sortedColumn, setSortedColumn] = useState<SortedColumn>({
|
|
241
263
|
dataKey: 'color',
|
|
242
264
|
sortDirection: 'descending',
|
|
243
265
|
});
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
266
|
+
const initialSortKey = sortedColumn.dataKey ?? 'color';
|
|
267
|
+
const [tableData, setTableData] = useState<SortableRow[]>([
|
|
268
|
+
...(sortedColumn.sortDirection === 'ascending'
|
|
269
|
+
? sortAscending(initialData, initialSortKey)
|
|
270
|
+
: sortDescending(initialData, initialSortKey)),
|
|
248
271
|
]);
|
|
249
|
-
const handleSort = (event:
|
|
250
|
-
const
|
|
272
|
+
const handleSort = (event: EventWithColumnKey) => {
|
|
273
|
+
const sortedKey =
|
|
274
|
+
typeof event.sortedKey === 'string' ? event.sortedKey : undefined;
|
|
275
|
+
if (!sortedKey) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const newSortDirection = getNewSortDirection(sortedKey, sortedColumn);
|
|
251
279
|
setSortedColumn({
|
|
252
|
-
dataKey:
|
|
280
|
+
dataKey: sortedKey,
|
|
253
281
|
sortDirection: newSortDirection,
|
|
254
282
|
});
|
|
255
283
|
};
|
|
@@ -279,31 +307,37 @@ export const SortablewithDefaultSortedColumn = () => {
|
|
|
279
307
|
};
|
|
280
308
|
|
|
281
309
|
export const SortableAndLoading = () => {
|
|
282
|
-
|
|
283
|
-
const sortDescending = (arrOfObj, key) =>
|
|
310
|
+
const sortDescending = (arrOfObj: SortableRow[], key: string) =>
|
|
284
311
|
[...arrOfObj].sort((a, b) => (b[key] > a[key] ? 1 : -1));
|
|
285
|
-
|
|
286
|
-
const sortAscending = (arrOfObj, key) =>
|
|
312
|
+
const sortAscending = (arrOfObj: SortableRow[], key: string) =>
|
|
287
313
|
[...arrOfObj].sort((a, b) => (a[key] > b[key] ? 1 : -1));
|
|
288
|
-
const getNewSortDirection = (
|
|
314
|
+
const getNewSortDirection = (
|
|
315
|
+
sortedKey: string,
|
|
316
|
+
currentSortedColumn: SortedColumn
|
|
317
|
+
) => {
|
|
289
318
|
if (
|
|
290
|
-
|
|
319
|
+
sortedKey === currentSortedColumn.dataKey &&
|
|
291
320
|
currentSortedColumn.sortDirection === 'ascending'
|
|
292
321
|
)
|
|
293
322
|
return 'descending';
|
|
294
323
|
return 'ascending';
|
|
295
324
|
};
|
|
296
|
-
const initialData = [
|
|
325
|
+
const initialData: SortableRow[] = [
|
|
297
326
|
{ id: 1, color: 'red', flavor: 'vanilla' },
|
|
298
327
|
{ id: 2, color: 'green', flavor: 'strawberry' },
|
|
299
328
|
{ id: 3, color: 'blue', flavor: 'chocolate' },
|
|
300
329
|
];
|
|
301
|
-
const [sortedColumn, setSortedColumn] = useState<
|
|
302
|
-
const [tableData, setTableData] = useState(initialData);
|
|
303
|
-
const handleSort = (event:
|
|
304
|
-
const
|
|
330
|
+
const [sortedColumn, setSortedColumn] = useState<SortedColumn>({});
|
|
331
|
+
const [tableData, setTableData] = useState<SortableRow[]>(initialData);
|
|
332
|
+
const handleSort = (event: EventWithColumnKey) => {
|
|
333
|
+
const sortedKey =
|
|
334
|
+
typeof event.sortedKey === 'string' ? event.sortedKey : undefined;
|
|
335
|
+
if (!sortedKey) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const newSortDirection = getNewSortDirection(sortedKey, sortedColumn);
|
|
305
339
|
setSortedColumn({
|
|
306
|
-
dataKey:
|
|
340
|
+
dataKey: sortedKey,
|
|
307
341
|
sortDirection: newSortDirection,
|
|
308
342
|
});
|
|
309
343
|
};
|
|
@@ -652,13 +686,25 @@ export const TruncateOverflow = () =>
|
|
|
652
686
|
|
|
653
687
|
export const CustomActions = () =>
|
|
654
688
|
(() => {
|
|
655
|
-
const renderFlavor = (cell
|
|
656
|
-
const
|
|
689
|
+
const renderFlavor = (cell?: Cell, row?: Row, index?: number) => {
|
|
690
|
+
const flavorCell = cell as { href?: string; name?: string } | undefined;
|
|
691
|
+
const flavorRow = row as { id?: number } | undefined;
|
|
692
|
+
const rows = [
|
|
693
|
+
{
|
|
694
|
+
href: flavorCell?.href ?? '',
|
|
695
|
+
name: flavorCell?.name ?? '',
|
|
696
|
+
id: flavorRow?.id ?? 0,
|
|
697
|
+
index,
|
|
698
|
+
},
|
|
699
|
+
];
|
|
657
700
|
const columns = [
|
|
658
701
|
{
|
|
659
702
|
heading: 'Url',
|
|
660
703
|
dataKey: 'href',
|
|
661
|
-
render: (cell
|
|
704
|
+
render: (cell?: Cell) => {
|
|
705
|
+
const href = typeof cell === 'string' ? cell : '';
|
|
706
|
+
return <a href={href}>{href}</a>;
|
|
707
|
+
},
|
|
662
708
|
},
|
|
663
709
|
{ heading: 'Name', dataKey: 'name' },
|
|
664
710
|
{ heading: 'ID', dataKey: 'id' },
|
|
@@ -672,7 +718,6 @@ export const CustomActions = () =>
|
|
|
672
718
|
{
|
|
673
719
|
heading: 'Based on the cell/row',
|
|
674
720
|
dataKey: 'flavor',
|
|
675
|
-
// @ts-ignore
|
|
676
721
|
render: renderFlavor,
|
|
677
722
|
},
|
|
678
723
|
{ heading: 'Any custom JSX', render: () => <Button>Do anything</Button> },
|
|
@@ -706,7 +751,12 @@ export const EmptyCellPlaceholder = () =>
|
|
|
706
751
|
{
|
|
707
752
|
heading: 'Price',
|
|
708
753
|
dataKey: 'price',
|
|
709
|
-
render: (cell
|
|
754
|
+
render: (cell?: Cell) => {
|
|
755
|
+
if (typeof cell === 'number' || typeof cell === 'string') {
|
|
756
|
+
return cell ? `$${cell}` : null;
|
|
757
|
+
}
|
|
758
|
+
return null;
|
|
759
|
+
},
|
|
710
760
|
emptyCellPlaceholder: '$0.00',
|
|
711
761
|
},
|
|
712
762
|
];
|
|
@@ -90,7 +90,7 @@ const createReducer =
|
|
|
90
90
|
handlers: THandlers
|
|
91
91
|
) =>
|
|
92
92
|
(state: TState = initialState, action: TAction) => {
|
|
93
|
-
if (
|
|
93
|
+
if (Object.prototype.hasOwnProperty.call(handlers, action.type)) {
|
|
94
94
|
// eslint-disable-line
|
|
95
95
|
return handlers[action.type](state, action);
|
|
96
96
|
}
|
|
@@ -4,6 +4,7 @@ import { ToastContainer, ToastPosition, toast } from './';
|
|
|
4
4
|
import { Button } from '../Button/Button';
|
|
5
5
|
import { Table } from '../Table/Table';
|
|
6
6
|
import { Box } from '../Box/Box';
|
|
7
|
+
import { Cell, Column as ColumnType } from 'src/types';
|
|
7
8
|
|
|
8
9
|
const meta: Meta<typeof ToastContainer> = {
|
|
9
10
|
title: 'Components/Toast',
|
|
@@ -84,12 +85,12 @@ export const Column = () =>
|
|
|
84
85
|
description: 'Whether to render a compact toast (smaller padding)',
|
|
85
86
|
},
|
|
86
87
|
];
|
|
87
|
-
const columnConfig = [
|
|
88
|
+
const columnConfig: ColumnType[] = [
|
|
88
89
|
{ heading: 'Name', dataKey: 'name' },
|
|
89
90
|
{
|
|
90
91
|
heading: 'Type',
|
|
91
92
|
dataKey: 'type',
|
|
92
|
-
render: (cell
|
|
93
|
+
render: (cell?: Cell) => <code style={codePreviewStyle}>{cell}</code>,
|
|
93
94
|
},
|
|
94
95
|
{ heading: 'Description', dataKey: 'description' },
|
|
95
96
|
];
|
|
@@ -258,10 +258,11 @@ describe('Toast', () => {
|
|
|
258
258
|
test('Async Success', async () => {
|
|
259
259
|
render(<ToastContainer />);
|
|
260
260
|
|
|
261
|
-
const myPromise = new Promise(
|
|
261
|
+
const myPromise = new Promise((resolve) => {
|
|
262
262
|
// eslint-disable-line no-async-promise-executor
|
|
263
|
-
|
|
264
|
-
|
|
263
|
+
wait(1000).then(() => {
|
|
264
|
+
resolve('yay');
|
|
265
|
+
});
|
|
265
266
|
});
|
|
266
267
|
|
|
267
268
|
act(() => {
|
|
@@ -287,10 +288,11 @@ describe('Toast', () => {
|
|
|
287
288
|
test('Async Error', async () => {
|
|
288
289
|
render(<ToastContainer />);
|
|
289
290
|
|
|
290
|
-
const myPromise = new Promise(
|
|
291
|
+
const myPromise = new Promise((_resolve, reject) => {
|
|
291
292
|
// eslint-disable-line no-async-promise-executor
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
wait(1000).then(() => {
|
|
294
|
+
reject('boo'); // eslint-disable-line prefer-promise-reject-errors
|
|
295
|
+
});
|
|
294
296
|
});
|
|
295
297
|
|
|
296
298
|
act(() => {
|
package/src/docs/Colors.mdx
CHANGED
|
@@ -31,19 +31,6 @@ import designTokens from '@hyphen/hyphen-design-tokens/build/json/variables.json
|
|
|
31
31
|
return acc;
|
|
32
32
|
}, {})}
|
|
33
33
|
/>
|
|
34
|
-
<ColorItem
|
|
35
|
-
title="color-base-primary"
|
|
36
|
-
subtitle="Primary"
|
|
37
|
-
colors={Object.keys(designTokens.color.base.primary).reduce(
|
|
38
|
-
(acc, item, i) => {
|
|
39
|
-
acc[item] = Object.keys(designTokens.color.base.primary).map(
|
|
40
|
-
(g) => designTokens.color.base.primary[g].value
|
|
41
|
-
)[i];
|
|
42
|
-
return acc;
|
|
43
|
-
},
|
|
44
|
-
{}
|
|
45
|
-
)}
|
|
46
|
-
/>
|
|
47
34
|
<ColorItem
|
|
48
35
|
title="color-base-red"
|
|
49
36
|
subtitle="Red"
|
package/src/lib/getColumnKeys.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Column } from '../types';
|
|
|
5
5
|
export const getColumnKeys = (columns: Column[]): Key[] => {
|
|
6
6
|
const INTERNAL_KEY_PREFIX = 'columnKeyPrefix';
|
|
7
7
|
const columnKeys: React.Key[] = [];
|
|
8
|
-
const keys: Record<
|
|
8
|
+
const keys: Record<string, boolean> = {};
|
|
9
9
|
|
|
10
10
|
columns.forEach((column) => {
|
|
11
11
|
const { key, dataKey } = column || {};
|
|
@@ -15,10 +15,10 @@ export const getColumnKeys = (columns: Column[]): Key[] => {
|
|
|
15
15
|
|
|
16
16
|
let mergedKey = key || shapedDataKey || INTERNAL_KEY_PREFIX;
|
|
17
17
|
|
|
18
|
-
while (keys[mergedKey
|
|
18
|
+
while (keys[String(mergedKey)]) {
|
|
19
19
|
mergedKey = `${mergedKey}_next`;
|
|
20
20
|
}
|
|
21
|
-
keys[mergedKey
|
|
21
|
+
keys[String(mergedKey)] = true;
|
|
22
22
|
|
|
23
23
|
columnKeys.push(mergedKey);
|
|
24
24
|
});
|
package/src/lib/mergeRefs.ts
CHANGED
package/src/lib/tokens.ts
CHANGED
|
@@ -93,7 +93,7 @@ export const BORDER_COLOR_OPTIONS = Object.keys(
|
|
|
93
93
|
// export const BORDER_COLOR_VALUES = designTokens.color.border;
|
|
94
94
|
|
|
95
95
|
export const FONT_SIZE_OPTIONS = Object.keys(
|
|
96
|
-
|
|
96
|
+
designTokens.size['font-size']
|
|
97
97
|
) as FontSize[];
|
|
98
98
|
// export const FONT_SIZE_VALUES = Object.values(designTokens.size['font-size']);
|
|
99
99
|
|
|
@@ -103,7 +103,7 @@ export const FONT_FAMILY_OPTIONS = Object.keys(
|
|
|
103
103
|
// export const FONT_FAMILY_VALUES = designTokens.assets['font-family'];
|
|
104
104
|
|
|
105
105
|
export const FONT_WEIGHT_OPTIONS = Object.keys(
|
|
106
|
-
|
|
106
|
+
designTokens.size['font-weight']
|
|
107
107
|
) as FontWeight[];
|
|
108
108
|
// export const FONT_WEIGHT_VALUES = designTokens.size['font-weight'];
|
|
109
109
|
|
|
@@ -112,7 +112,7 @@ export const HEADING_SIZE_OPTIONS = Object.keys(
|
|
|
112
112
|
) as HeadingSize[];
|
|
113
113
|
|
|
114
114
|
export const HEIGHT_OPTIONS = Object.keys(
|
|
115
|
-
|
|
115
|
+
designTokens.size.dimension
|
|
116
116
|
) as HeightSize[];
|
|
117
117
|
// export const HEIGHT_VALUES = designTokens.size.dimension;
|
|
118
118
|
|
|
@@ -127,7 +127,7 @@ export const SPACING_OPTIONS = Object.keys(
|
|
|
127
127
|
// export const SPACING_VALUES = designTokens.size.spacing;
|
|
128
128
|
|
|
129
129
|
export const WIDTH_OPTIONS = Object.keys(
|
|
130
|
-
|
|
130
|
+
designTokens.size.dimension
|
|
131
131
|
) as WidthSize[];
|
|
132
132
|
// export const WIDTH_VALUES = designTokens.size.dimension;
|
|
133
133
|
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode, MouseEvent, KeyboardEvent } from 'react';
|
|
2
|
-
import { AlertVariant } from './Alert.types';
|
|
3
|
-
export interface AlertProps {
|
|
4
|
-
/**
|
|
5
|
-
* Custom class to apply to the alert.
|
|
6
|
-
*/
|
|
7
|
-
className?: string;
|
|
8
|
-
/**
|
|
9
|
-
* Whether the alert as an icon that corresponds to its variant (Success, warning, etc.).
|
|
10
|
-
*/
|
|
11
|
-
hasIcon?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Renders a version of the alert with smaller padding.
|
|
14
|
-
*/
|
|
15
|
-
isCompact?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated Use children instead. The text message or ReactNode to be rendered in the alert.
|
|
18
|
-
*/
|
|
19
|
-
message?: string | ReactNode;
|
|
20
|
-
/**
|
|
21
|
-
* Whether the alert can be closed by the user. If `true` it will render
|
|
22
|
-
* the 'close' icon on the right hand side of the alert.
|
|
23
|
-
*/
|
|
24
|
-
onClose?: (event: MouseEvent<HTMLOrSVGElement> | KeyboardEvent<HTMLSpanElement>) => void;
|
|
25
|
-
/**
|
|
26
|
-
* A render function that returns JSX if preferred over a static ReactNode or string.
|
|
27
|
-
*/
|
|
28
|
-
render?: () => ReactNode;
|
|
29
|
-
/**
|
|
30
|
-
* The title for the alert.
|
|
31
|
-
*/
|
|
32
|
-
title?: string;
|
|
33
|
-
/**
|
|
34
|
-
* The type/color of the alert to show.
|
|
35
|
-
*/
|
|
36
|
-
variant?: AlertVariant;
|
|
37
|
-
/**
|
|
38
|
-
* Additional props to be spread to rendered element
|
|
39
|
-
*/
|
|
40
|
-
[x: string]: any;
|
|
41
|
-
}
|
|
42
|
-
export declare const Alert: React.NamedExoticComponent<AlertProps>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Alert } from './Alert';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
declare const meta: Meta<typeof Alert>;
|
|
5
|
-
export default meta;
|
|
6
|
-
type Story = StoryObj<typeof Alert>;
|
|
7
|
-
export declare const Overview: Story;
|
|
8
|
-
export declare const Compact: Story;
|
|
9
|
-
export declare const WithCustomContent: Story;
|
|
10
|
-
export declare const Variants: Story;
|
|
11
|
-
export declare const ClosableAlert: () => React.JSX.Element;
|
|
12
|
-
export declare const Closable: Story;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import { FontSize, BaseSpacing, ResponsiveProp } from '../../types';
|
|
3
|
-
import { BoxProps } from '../Box/Box';
|
|
4
|
-
export type BadgeSize = 'sm' | 'md' | 'lg';
|
|
5
|
-
export type BadgeVariant = 'light-grey' | 'dark-grey' | 'inverse' | 'green' | 'yellow' | 'blue' | 'red' | 'purple' | 'hyphen';
|
|
6
|
-
export type BadgeSizeAttributes = {
|
|
7
|
-
fontSize: FontSize;
|
|
8
|
-
padding: BaseSpacing;
|
|
9
|
-
};
|
|
10
|
-
export interface BadgeProps extends BoxProps {
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated Use children instead. The text message or ReactNode to be rendered in the badge.
|
|
13
|
-
*/
|
|
14
|
-
message?: string | ReactNode;
|
|
15
|
-
/**
|
|
16
|
-
* The size of the button.
|
|
17
|
-
*/
|
|
18
|
-
size?: BadgeSize | ResponsiveProp<BadgeSize>;
|
|
19
|
-
/**
|
|
20
|
-
* The type/color of the badge to show.
|
|
21
|
-
*/
|
|
22
|
-
variant?: BadgeVariant;
|
|
23
|
-
}
|
|
24
|
-
export declare const Badge: React.ForwardRefExoticComponent<Omit<BadgeProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Badge } from './Badge';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
-
declare const meta: Meta<typeof Badge>;
|
|
4
|
-
export default meta;
|
|
5
|
-
type Story = StoryObj<typeof Badge>;
|
|
6
|
-
export declare const Overview: Story;
|
|
7
|
-
export declare const Variants: Story;
|
|
8
|
-
export declare const Sizes: Story;
|