@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.
Files changed (70) hide show
  1. package/dist/css/fonts.css +5 -3
  2. package/dist/css/fonts.css.map +1 -0
  3. package/dist/css/index.css +370 -222
  4. package/dist/css/index.css.map +1 -0
  5. package/dist/css/reset.css +5 -3
  6. package/dist/css/reset.css.map +1 -0
  7. package/dist/css/utilities.css +487 -43
  8. package/dist/css/utilities.css.map +1 -0
  9. package/dist/css/variables.css +180 -33
  10. package/dist/css/variables.css.map +1 -0
  11. package/dist/hyphen-components.cjs.development.js +250 -317
  12. package/dist/hyphen-components.cjs.development.js.map +1 -1
  13. package/dist/hyphen-components.cjs.production.min.js +2 -2
  14. package/dist/hyphen-components.cjs.production.min.js.map +1 -1
  15. package/dist/hyphen-components.esm.js +204 -271
  16. package/dist/hyphen-components.esm.js.map +1 -1
  17. package/dist/index.d.ts +25 -60
  18. package/package.json +4 -4
  19. package/src/components/Alert/Alert.mdx +1 -1
  20. package/src/components/Alert/Alert.module.scss +29 -34
  21. package/src/components/Alert/Alert.stories.tsx +11 -3
  22. package/src/components/Alert/Alert.test.tsx +17 -11
  23. package/src/components/Alert/Alert.tsx +9 -16
  24. package/src/components/Badge/Badge.mdx +46 -4
  25. package/src/components/Badge/Badge.module.scss +235 -185
  26. package/src/components/Badge/Badge.stories.tsx +126 -36
  27. package/src/components/Badge/Badge.test.tsx +180 -21
  28. package/src/components/Badge/Badge.tsx +56 -21
  29. package/src/components/Button/Button.module.scss +1 -1
  30. package/src/components/CheckboxInput/components/Checkbox.module.scss +2 -2
  31. package/src/components/Drawer/Drawer.mdx +14 -16
  32. package/src/components/Drawer/Drawer.module.scss +1 -1
  33. package/src/components/DropdownMenu/DropdownMenu.tsx +6 -8
  34. package/src/components/Formik/Formik.stories.tsx +3 -5
  35. package/src/components/Formik/FormikTimePicker/FormikTimePicker.test.tsx +34 -67
  36. package/src/components/Formik/FormikTimePicker/FormikTimePicker.tsx +0 -2
  37. package/src/components/Modal/Modal.module.scss +1 -1
  38. package/src/components/RadioGroup/RadioInput/RadioInput.module.scss +2 -2
  39. package/src/components/SelectInput/SelectInput.module.scss +1 -1
  40. package/src/components/SelectInputInset/SelectInputInset.module.scss +1 -1
  41. package/src/components/SelectInputNative/SelectInputNative.module.scss +1 -1
  42. package/src/components/Switch/Switch.module.scss +1 -1
  43. package/src/components/Table/Table.stories.tsx +4 -4
  44. package/src/components/TextInput/TextInput.module.scss +1 -1
  45. package/src/components/TextInputInset/TextInputInset.module.scss +1 -1
  46. package/src/components/TextareaInput/TextareaInput.module.scss +1 -1
  47. package/src/components/TextareaInputInset/TextareaInputInset.module.scss +1 -1
  48. package/src/components/TimePicker/TimePicker.mdx +3 -11
  49. package/src/components/TimePicker/TimePicker.stories.tsx +61 -60
  50. package/src/components/TimePicker/TimePicker.test.tsx +76 -7
  51. package/src/components/TimePicker/TimePicker.tsx +37 -7
  52. package/src/components/Toggle/Toggle.module.scss +1 -1
  53. package/src/components/ToggleGroup/ToggleGroup.module.scss +1 -1
  54. package/src/components/Tooltip/Tooltip.stories.tsx +1 -1
  55. package/src/docs/Colors.mdx +13 -0
  56. package/src/index.ts +0 -2
  57. package/src/styles/display.scss +1 -1
  58. package/src/styles/flex.scss +1 -1
  59. package/src/styles/overflow.scss +2 -0
  60. package/src/styles/position.scss +2 -0
  61. package/src/styles/text-align.scss +2 -0
  62. package/src/styles/utilities.scss +10 -9
  63. package/src/styles/variables/index.scss +2 -1
  64. package/src/styles/white-space.scss +2 -0
  65. package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.test.tsx +0 -175
  66. package/src/components/Formik/FormikTimePickerNative/FormikTimePickerNative.tsx +0 -38
  67. package/src/components/TimePickerNative/TimePickerNative.mdx +0 -67
  68. package/src/components/TimePickerNative/TimePickerNative.stories.tsx +0 -150
  69. package/src/components/TimePickerNative/TimePickerNative.test.tsx +0 -117
  70. 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
- };