@hyphen/hyphen-components 7.10.0 → 8.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/dist/css/fonts.css +5 -3
- package/dist/css/fonts.css.map +1 -0
- package/dist/css/index.css +370 -222
- package/dist/css/index.css.map +1 -0
- package/dist/css/reset.css +5 -3
- package/dist/css/reset.css.map +1 -0
- package/dist/css/utilities.css +487 -43
- package/dist/css/utilities.css.map +1 -0
- package/dist/css/variables.css +180 -33
- package/dist/css/variables.css.map +1 -0
- package/dist/hyphen-components.cjs.development.js +250 -317
- 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 +204 -271
- package/dist/hyphen-components.esm.js.map +1 -1
- package/dist/index.d.ts +25 -60
- package/package.json +4 -4
- 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/Button/Button.module.scss +1 -1
- package/src/components/CheckboxInput/components/Checkbox.module.scss +2 -2
- package/src/components/Drawer/Drawer.mdx +14 -16
- package/src/components/Drawer/Drawer.module.scss +1 -1
- package/src/components/DropdownMenu/DropdownMenu.tsx +6 -8
- 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/Modal/Modal.module.scss +1 -1
- package/src/components/RadioGroup/RadioInput/RadioInput.module.scss +2 -2
- package/src/components/SelectInput/SelectInput.module.scss +1 -1
- package/src/components/SelectInputInset/SelectInputInset.module.scss +1 -1
- package/src/components/SelectInputNative/SelectInputNative.module.scss +1 -1
- package/src/components/Switch/Switch.module.scss +1 -1
- package/src/components/Table/Table.stories.tsx +4 -4
- package/src/components/TextInput/TextInput.module.scss +1 -1
- package/src/components/TextInputInset/TextInputInset.module.scss +1 -1
- package/src/components/TextareaInput/TextareaInput.module.scss +1 -1
- package/src/components/TextareaInputInset/TextareaInputInset.module.scss +1 -1
- 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/Toggle/Toggle.module.scss +1 -1
- package/src/components/ToggleGroup/ToggleGroup.module.scss +1 -1
- package/src/components/Tooltip/Tooltip.stories.tsx +1 -1
- package/src/docs/Colors.mdx +13 -0
- package/src/index.ts +0 -2
- package/src/styles/display.scss +1 -1
- package/src/styles/flex.scss +1 -1
- package/src/styles/overflow.scss +2 -0
- package/src/styles/position.scss +2 -0
- package/src/styles/text-align.scss +2 -0
- package/src/styles/utilities.scss +10 -9
- package/src/styles/variables/index.scss +2 -1
- package/src/styles/white-space.scss +2 -0
- 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,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
|
-
};
|