@hyphen/hyphen-components 7.9.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/fonts.css +1 -1
- package/dist/css/index.css +292 -150
- package/dist/css/reset.css +1 -1
- package/dist/css/utilities.css +480 -38
- package/dist/css/variables.css +170 -25
- package/dist/hyphen-components.cjs.development.js +244 -311
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +2 -2
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +198 -265
- package/dist/hyphen-components.esm.js.map +1 -1
- package/dist/index.d.ts +25 -60
- package/package.json +3 -3
- package/src/components/Alert/Alert.mdx +1 -1
- package/src/components/Alert/Alert.module.scss +29 -34
- package/src/components/Alert/Alert.stories.tsx +11 -3
- package/src/components/Alert/Alert.test.tsx +17 -11
- package/src/components/Alert/Alert.tsx +9 -16
- package/src/components/Badge/Badge.mdx +46 -4
- package/src/components/Badge/Badge.module.scss +235 -185
- package/src/components/Badge/Badge.stories.tsx +126 -36
- package/src/components/Badge/Badge.test.tsx +180 -21
- package/src/components/Badge/Badge.tsx +56 -21
- package/src/components/Drawer/Drawer.mdx +14 -16
- package/src/components/Formik/Formik.stories.tsx +3 -5
- package/src/components/Formik/FormikTimePicker/FormikTimePicker.test.tsx +34 -67
- package/src/components/Formik/FormikTimePicker/FormikTimePicker.tsx +0 -2
- package/src/components/Table/Table.stories.tsx +4 -4
- package/src/components/TimePicker/TimePicker.mdx +3 -11
- package/src/components/TimePicker/TimePicker.stories.tsx +61 -60
- package/src/components/TimePicker/TimePicker.test.tsx +76 -7
- package/src/components/TimePicker/TimePicker.tsx +37 -7
- package/src/components/Tooltip/Tooltip.stories.tsx +1 -1
- package/src/docs/Colors.mdx +13 -0
- package/src/index.ts +0 -2
- package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.test.tsx +0 -175
- package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.tsx +0 -38
- package/src/components/TimePickerNative/TimePickerNative.mdx +0 -67
- package/src/components/TimePickerNative/TimePickerNative.stories.tsx +0 -150
- package/src/components/TimePickerNative/TimePickerNative.test.tsx +0 -117
- package/src/components/TimePickerNative/TimePickerNative.tsx +0 -93
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Canvas, Meta, ArgTypes } from '@storybook/addon-docs/blocks';
|
|
2
|
-
import { TimePickerNative } from './TimePickerNative';
|
|
3
|
-
import * as Stories from './TimePickerNative.stories';
|
|
4
|
-
|
|
5
|
-
<Meta of={Stories} />
|
|
6
|
-
|
|
7
|
-
# TimePickerNative
|
|
8
|
-
|
|
9
|
-
Use a TimePickerNative when you want users to select from a list of a available times agnostic of date.
|
|
10
|
-
|
|
11
|
-
_NOTE:_ This component is abstracted from the [SelectInputNative](?path=/docs/components-selectinputnative-overview--default-story)
|
|
12
|
-
and as such includes the same underlying props interface with an added method for generating the time options automatically.
|
|
13
|
-
|
|
14
|
-
_ABOUT TIME FORMAT:_ The value returned will always be a JS ISO date string, like this: `2016-07-13T18:46:01.933Z`.
|
|
15
|
-
|
|
16
|
-
## Props
|
|
17
|
-
|
|
18
|
-
<ArgTypes of={TimePickerNative} />
|
|
19
|
-
|
|
20
|
-
## Default
|
|
21
|
-
|
|
22
|
-
<Canvas of={Stories.Default} />
|
|
23
|
-
|
|
24
|
-
## With A Specific Interval
|
|
25
|
-
|
|
26
|
-
Pass an `interval` (seconds) value to determine how many times get generated as options.
|
|
27
|
-
The example below uses `3600` --> 1 Hour Intervals
|
|
28
|
-
|
|
29
|
-
<Canvas of={Stories.WithASpecificInterval} />
|
|
30
|
-
|
|
31
|
-
## With Min and Max Times
|
|
32
|
-
|
|
33
|
-
You can determine the range of times to be shown by capping the start and end times.
|
|
34
|
-
Use `startTime` and `endTime` for this. The expected values for `hour` and `minute` properties
|
|
35
|
-
are `0-24` and `0-60` respectively.
|
|
36
|
-
|
|
37
|
-
IMPORTANT: `startTime` is inclusive, and `endTime` is exclusive. This is to avoid
|
|
38
|
-
the options showing the startTime twice when using a 24-hour cycle.
|
|
39
|
-
|
|
40
|
-
See example below where we want to show 15 minute increments starting at 9:00AM and ending at 3:30PM.
|
|
41
|
-
|
|
42
|
-
<Canvas of={Stories.WithMinAndMaxTimes} />
|
|
43
|
-
|
|
44
|
-
## With Custom Date Display
|
|
45
|
-
|
|
46
|
-
The labels for the dropdwon options are governed by JS `toLocaleTimeString`, and as such
|
|
47
|
-
options are available to customize these.
|
|
48
|
-
|
|
49
|
-
NOTE: that the option values are always returned as ISO strings regardless of the label display option.
|
|
50
|
-
|
|
51
|
-
The example below is shown in military (24-hour) time.
|
|
52
|
-
|
|
53
|
-
<Canvas of={Stories.WithCustomDateDisplay} />
|
|
54
|
-
|
|
55
|
-
## Help Text
|
|
56
|
-
|
|
57
|
-
<Canvas of={Stories.HelpText} />
|
|
58
|
-
|
|
59
|
-
## Sizes
|
|
60
|
-
|
|
61
|
-
Set the size of the input to `sm`, `md` or `lg`. `md` is the default size.
|
|
62
|
-
|
|
63
|
-
<Canvas of={Stories.Sizes} />
|
|
64
|
-
|
|
65
|
-
## Component Design Tokens
|
|
66
|
-
|
|
67
|
-
This component shares component design tokens with all form controls. For a complete list of tokens, see the [Theming Form Controls documentation](/docs/theming-form-controls--custom-theme-form).
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import type { Meta } from '@storybook/react-vite';
|
|
2
|
-
import React, { ChangeEvent, useState } from 'react';
|
|
3
|
-
import { TimePickerNative } from './TimePickerNative';
|
|
4
|
-
import { Box } from '../Box/Box';
|
|
5
|
-
|
|
6
|
-
const meta: Meta<typeof TimePickerNative> = {
|
|
7
|
-
title: 'Components/TimePickerNative',
|
|
8
|
-
component: TimePickerNative,
|
|
9
|
-
parameters: {
|
|
10
|
-
controls: { hideNoControlsWarning: true },
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default meta;
|
|
15
|
-
|
|
16
|
-
export const Default = () => {
|
|
17
|
-
const [value, setValue] = useState<string | null>(null);
|
|
18
|
-
return (
|
|
19
|
-
<Box>
|
|
20
|
-
<TimePickerNative
|
|
21
|
-
id="defaultTimePickerNative"
|
|
22
|
-
name="defaultTimePickerNative"
|
|
23
|
-
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
24
|
-
setValue(event.target.value);
|
|
25
|
-
}}
|
|
26
|
-
label="Pick a Time"
|
|
27
|
-
value={value}
|
|
28
|
-
/>
|
|
29
|
-
</Box>
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const WithASpecificInterval = () => {
|
|
34
|
-
const [value, setValue] = useState<string | null>(null);
|
|
35
|
-
return (
|
|
36
|
-
<Box>
|
|
37
|
-
<TimePickerNative
|
|
38
|
-
id="intervalTimePickerNative"
|
|
39
|
-
name="intervalTimePickerNative"
|
|
40
|
-
onChange={(event: ChangeEvent<HTMLInputElement>) =>
|
|
41
|
-
setValue(event.target.value)
|
|
42
|
-
}
|
|
43
|
-
value={value}
|
|
44
|
-
label="Pick a Time"
|
|
45
|
-
interval={3600}
|
|
46
|
-
/>
|
|
47
|
-
</Box>
|
|
48
|
-
);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const WithMinAndMaxTimes = () => {
|
|
52
|
-
const [value, setValue] = useState<string | null>(null);
|
|
53
|
-
return (
|
|
54
|
-
<Box>
|
|
55
|
-
<TimePickerNative
|
|
56
|
-
id="startEnd"
|
|
57
|
-
name="startEnd"
|
|
58
|
-
onChange={(event: ChangeEvent<HTMLInputElement>) =>
|
|
59
|
-
setValue(event.target.value)
|
|
60
|
-
}
|
|
61
|
-
value={value}
|
|
62
|
-
label="Pick a Time"
|
|
63
|
-
startTime={{ hour: 9, minute: 0 }}
|
|
64
|
-
endTime={{ hour: 15, minute: 31 }}
|
|
65
|
-
/>
|
|
66
|
-
</Box>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const WithCustomDateDisplay = () => {
|
|
71
|
-
const [value, setValue] = useState<string | null>(null);
|
|
72
|
-
return (
|
|
73
|
-
<Box>
|
|
74
|
-
<TimePickerNative
|
|
75
|
-
id="customDate"
|
|
76
|
-
name="customDate"
|
|
77
|
-
onChange={(event: ChangeEvent<HTMLInputElement>) =>
|
|
78
|
-
setValue(event.target.value)
|
|
79
|
-
}
|
|
80
|
-
value={value}
|
|
81
|
-
label="Pick a Time"
|
|
82
|
-
startTime={{ hour: 9, minute: 0 }}
|
|
83
|
-
endTime={{ hour: 15, minute: 31 }}
|
|
84
|
-
dateDisplayOptions={{
|
|
85
|
-
hour12: false,
|
|
86
|
-
hour: '2-digit',
|
|
87
|
-
minute: '2-digit',
|
|
88
|
-
}}
|
|
89
|
-
/>
|
|
90
|
-
</Box>
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export const HelpText = () => {
|
|
95
|
-
const [value, setValue] = useState<string | null>(null);
|
|
96
|
-
return (
|
|
97
|
-
<Box>
|
|
98
|
-
<TimePickerNative
|
|
99
|
-
id="helpText"
|
|
100
|
-
name="helpText"
|
|
101
|
-
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
102
|
-
setValue(event.target.value);
|
|
103
|
-
}}
|
|
104
|
-
label="Pick a Time"
|
|
105
|
-
value={value}
|
|
106
|
-
helpText="pick a time, any time..."
|
|
107
|
-
/>
|
|
108
|
-
</Box>
|
|
109
|
-
);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export const Sizes = () => {
|
|
113
|
-
const [value, setValue] = useState<string | null>(null);
|
|
114
|
-
const [value1, setValue1] = useState<string | null>(null);
|
|
115
|
-
const [value2, setValue2] = useState<string | null>(null);
|
|
116
|
-
return (
|
|
117
|
-
<Box gap="md">
|
|
118
|
-
<TimePickerNative
|
|
119
|
-
id="smTimePickerNative"
|
|
120
|
-
name="smTimePickerNative"
|
|
121
|
-
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
122
|
-
setValue(event.target.value);
|
|
123
|
-
}}
|
|
124
|
-
label="Small"
|
|
125
|
-
value={value}
|
|
126
|
-
size="sm"
|
|
127
|
-
/>
|
|
128
|
-
<TimePickerNative
|
|
129
|
-
id="mdTimePickerNative"
|
|
130
|
-
name="mdTimePickerNative"
|
|
131
|
-
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
132
|
-
setValue1(event.target.value);
|
|
133
|
-
}}
|
|
134
|
-
label="Medium"
|
|
135
|
-
value={value1}
|
|
136
|
-
size="md"
|
|
137
|
-
/>
|
|
138
|
-
<TimePickerNative
|
|
139
|
-
id="lgTimePickerNative"
|
|
140
|
-
name="lgTimePickerNative"
|
|
141
|
-
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
142
|
-
setValue2(event.target.value);
|
|
143
|
-
}}
|
|
144
|
-
label="Large"
|
|
145
|
-
value={value2}
|
|
146
|
-
size="lg"
|
|
147
|
-
/>
|
|
148
|
-
</Box>
|
|
149
|
-
);
|
|
150
|
-
};
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { screen, render, fireEvent } from '@testing-library/react';
|
|
3
|
-
import { TimePickerNative } from './TimePickerNative';
|
|
4
|
-
|
|
5
|
-
describe('TimePickerNative', () => {
|
|
6
|
-
describe('Default', () => {
|
|
7
|
-
it('Renders a TimePickerNative (select) with default props', () => {
|
|
8
|
-
render(
|
|
9
|
-
<TimePickerNative
|
|
10
|
-
name="timePicker"
|
|
11
|
-
id="timePicker"
|
|
12
|
-
onChange={() => null}
|
|
13
|
-
value={null}
|
|
14
|
-
label="Select Time"
|
|
15
|
-
/>
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
const timePicker = screen.getByLabelText('Select Time');
|
|
19
|
-
|
|
20
|
-
const expectedTimes = [
|
|
21
|
-
'12:00 AM',
|
|
22
|
-
'12:15 AM',
|
|
23
|
-
'12:30 AM',
|
|
24
|
-
'12:45 AM',
|
|
25
|
-
'01:00 AM',
|
|
26
|
-
'01:15 AM',
|
|
27
|
-
];
|
|
28
|
-
expect(timePicker).toBeInTheDocument();
|
|
29
|
-
expectedTimes.forEach((time) => {
|
|
30
|
-
expect(screen.queryByText(time)).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('Min/Max & Interval', () => {
|
|
36
|
-
it('Renders correct options based on interval and start end times.', () => {
|
|
37
|
-
render(
|
|
38
|
-
<TimePickerNative
|
|
39
|
-
name="timePicker"
|
|
40
|
-
id="timePicker"
|
|
41
|
-
onChange={() => null}
|
|
42
|
-
value={null}
|
|
43
|
-
label="Select Time"
|
|
44
|
-
interval={3600}
|
|
45
|
-
startTime={{ hour: 9, minute: 0 }}
|
|
46
|
-
endTime={{ hour: 12, minute: 0 }}
|
|
47
|
-
/>
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const timePicker = screen.getByLabelText('Select Time');
|
|
51
|
-
|
|
52
|
-
const expectedTimes = ['09:00 AM', '10:00 AM', '11:00 AM'];
|
|
53
|
-
|
|
54
|
-
const notExpected = ['12:00 PM', '12:45 AM', '01:00 AM', '01:15 AM'];
|
|
55
|
-
expect(timePicker).toBeInTheDocument();
|
|
56
|
-
expectedTimes.forEach((time) => {
|
|
57
|
-
expect(screen.queryByText(time)).toBeInTheDocument();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
notExpected.forEach((time) => {
|
|
61
|
-
expect(screen.queryByText(time)).toBe(null);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('Custom Date Display', () => {
|
|
67
|
-
it('renders the times based on the options provided', () => {
|
|
68
|
-
render(
|
|
69
|
-
<TimePickerNative
|
|
70
|
-
name="timePicker"
|
|
71
|
-
id="timePicker"
|
|
72
|
-
onChange={() => null}
|
|
73
|
-
value={null}
|
|
74
|
-
label="Select Time"
|
|
75
|
-
dateDisplayOptions={{ hour12: false }}
|
|
76
|
-
startTime={{ hour: 13, minute: 0 }}
|
|
77
|
-
endTime={{ hour: 15, minute: 1 }}
|
|
78
|
-
interval={3600}
|
|
79
|
-
/>
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const timePicker = screen.getByLabelText('Select Time');
|
|
83
|
-
|
|
84
|
-
const expectedTimes = ['13:00:00', '14:00:00', '15:00:00'];
|
|
85
|
-
expect(timePicker).toBeInTheDocument();
|
|
86
|
-
expectedTimes.forEach((time) => {
|
|
87
|
-
expect(screen.queryByText(time)).toBeInTheDocument();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('Callback Handling', () => {
|
|
93
|
-
it('it fires an onchange callback with the correct value', async () => {
|
|
94
|
-
const mockedHandleChange = jest.fn(() => {}); // eslint-disable-line
|
|
95
|
-
|
|
96
|
-
render(
|
|
97
|
-
<TimePickerNative
|
|
98
|
-
name="timePicker"
|
|
99
|
-
id="timePicker"
|
|
100
|
-
onChange={mockedHandleChange}
|
|
101
|
-
value={null}
|
|
102
|
-
label="Select Time"
|
|
103
|
-
dateDisplayOptions={{ hour12: false }}
|
|
104
|
-
startTime={{ hour: 13, minute: 0 }}
|
|
105
|
-
endTime={{ hour: 15, minute: 1 }}
|
|
106
|
-
interval={3600}
|
|
107
|
-
/>
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const timePicker = screen.getByLabelText('Select Time');
|
|
111
|
-
|
|
112
|
-
fireEvent.change(timePicker, { target: { value: 'hello' } });
|
|
113
|
-
|
|
114
|
-
expect(mockedHandleChange).toBeCalledTimes(1);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
SelectInputNative,
|
|
4
|
-
SelectInputNativeProps,
|
|
5
|
-
} from '../SelectInputNative/SelectInputNative';
|
|
6
|
-
|
|
7
|
-
export interface TimePickerNativeProps
|
|
8
|
-
extends Omit<SelectInputNativeProps, 'options'> {
|
|
9
|
-
/**
|
|
10
|
-
* Options to govern the display of the option labels in the select.
|
|
11
|
-
* This is a direct passthrough to the second argument of JS `toLocaleTimeString`.
|
|
12
|
-
* [More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
|
|
13
|
-
*/
|
|
14
|
-
dateDisplayOptions?: Intl.DateTimeFormatOptions;
|
|
15
|
-
/**
|
|
16
|
-
* End hour and minute
|
|
17
|
-
*/
|
|
18
|
-
endTime?: { hour: number; minute: number };
|
|
19
|
-
/**
|
|
20
|
-
* Interval of displayed times (in seconds). Defaults to 900 seconds (15 minutes).
|
|
21
|
-
*/
|
|
22
|
-
interval?: number;
|
|
23
|
-
/**
|
|
24
|
-
* Locale(s) to be passed down in order to format the label values in the select.
|
|
25
|
-
* This corresponds to the first argument of JS `toLocaleTimeString`.
|
|
26
|
-
* [More](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
|
|
27
|
-
*/
|
|
28
|
-
locales?: string | string[];
|
|
29
|
-
/**
|
|
30
|
-
* Start hour and minute
|
|
31
|
-
*/
|
|
32
|
-
startTime?: { hour: number; minute: number };
|
|
33
|
-
/**
|
|
34
|
-
* Should be ISO timestamp as returned by `onChange`, and matching value of option object.
|
|
35
|
-
*/
|
|
36
|
-
value: SelectInputNativeProps['value'];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const TimePickerNative: FC<TimePickerNativeProps> = ({
|
|
40
|
-
id,
|
|
41
|
-
name,
|
|
42
|
-
label,
|
|
43
|
-
onChange,
|
|
44
|
-
value,
|
|
45
|
-
dateDisplayOptions = { hour: '2-digit', minute: '2-digit' },
|
|
46
|
-
endTime = undefined,
|
|
47
|
-
interval = 900,
|
|
48
|
-
locales = 'en-US',
|
|
49
|
-
placeholder = 'HH:MM',
|
|
50
|
-
startTime = undefined,
|
|
51
|
-
...restProps
|
|
52
|
-
}) => {
|
|
53
|
-
const generateTimes = () => {
|
|
54
|
-
const first = new Date();
|
|
55
|
-
first.setHours(startTime?.hour || 0, startTime?.minute || 0, 0, 0);
|
|
56
|
-
|
|
57
|
-
const last = new Date();
|
|
58
|
-
last.setHours(
|
|
59
|
-
endTime?.hour || first.getHours() + 24,
|
|
60
|
-
endTime?.minute || 0,
|
|
61
|
-
0,
|
|
62
|
-
0
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const timeOptions = [];
|
|
66
|
-
const currentTime: Date = new Date(first);
|
|
67
|
-
|
|
68
|
-
while (currentTime < last) {
|
|
69
|
-
timeOptions.push({
|
|
70
|
-
value: currentTime.toISOString(),
|
|
71
|
-
label: currentTime.toLocaleTimeString(locales, dateDisplayOptions),
|
|
72
|
-
});
|
|
73
|
-
currentTime.setSeconds(first.getSeconds() + interval);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return timeOptions;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const options = generateTimes();
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<SelectInputNative
|
|
83
|
-
{...restProps}
|
|
84
|
-
id={id}
|
|
85
|
-
name={name}
|
|
86
|
-
label={label}
|
|
87
|
-
onChange={onChange}
|
|
88
|
-
options={options}
|
|
89
|
-
placeholder={placeholder}
|
|
90
|
-
value={value}
|
|
91
|
-
/>
|
|
92
|
-
);
|
|
93
|
-
};
|