@hyphen/hyphen-components 7.0.0 → 7.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyphen/hyphen-components",
3
- "version": "7.0.0",
3
+ "version": "7.2.0",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "@hyphen"
@@ -62,7 +62,7 @@
62
62
  ],
63
63
  "dependencies": {
64
64
  "@emotion/react": "^11.14.0",
65
- "@hyphen/hyphen-design-tokens": "^6.0.0",
65
+ "@hyphen/hyphen-design-tokens": "^6.1.0",
66
66
  "@radix-ui/react-aspect-ratio": "^1.1.8",
67
67
  "@radix-ui/react-collapsible": "^1.1.12",
68
68
  "@radix-ui/react-dropdown-menu": "^2.1.16",
@@ -1,6 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { Meta } from '@storybook/react-vite';
3
3
  import { Box } from './Box';
4
+ import {
5
+ BACKGROUND_COLOR_OPTIONS,
6
+ BORDER_COLOR_OPTIONS,
7
+ FONT_COLOR_OPTIONS,
8
+ } from '../../lib/tokens';
4
9
 
5
10
  const meta: Meta<typeof Box> = {
6
11
  title: 'Components/Box',
@@ -72,60 +77,11 @@ export const Overview = () => (
72
77
  export const Background = () => {
73
78
  return (
74
79
  <Box gap="md">
75
- <Box background="primary" padding="md">
76
- primary
77
- </Box>
78
- <Box background="secondary" padding="md">
79
- secondary
80
- </Box>
81
- <Box background="tertiary" padding="md">
82
- tertiary
83
- </Box>
84
- <Box background="info" padding="md">
85
- info
86
- </Box>
87
- <Box background="warning" padding="md">
88
- warning
89
- </Box>
90
- <Box background="danger" padding="md">
91
- danger
92
- </Box>
93
- <Box background="inverse" color="inverse" padding="md">
94
- inverse
95
- </Box>
96
- <Box background="brand-yellow" padding="md">
97
- brand-yellow
98
- </Box>
99
- <Box background="brand-orange" padding="md">
100
- brand-orange
101
- </Box>
102
- <Box background="brand-magenta" padding="md">
103
- brand-magenta
104
- </Box>
105
- <Box color="white" background="brand-dark-grey" padding="md">
106
- brand-dark-grey
107
- </Box>
108
- <Box background="brand-cyan" padding="md">
109
- brand-cyan
110
- </Box>
111
- <Box background="brand-pink" padding="md">
112
- brand-pink
113
- </Box>
114
- <Box background="brand-light-purple" padding="md">
115
- brand-light-purple
116
- </Box>
117
- <Box color="white" background="brand-medium-purple" padding="md">
118
- brand-medium-purple
119
- </Box>
120
- <Box color="white" background="brand-dark-purple" padding="md">
121
- brand-dark-purple
122
- </Box>
123
- <Box color="white" background="chart-1" padding="md">
124
- chart-1
125
- </Box>
126
- <Box color="white" background="chart-2" padding="md">
127
- chart-2
128
- </Box>
80
+ {BACKGROUND_COLOR_OPTIONS.map((color) => (
81
+ <Box key={color} background={color} padding="md">
82
+ {color}
83
+ </Box>
84
+ ))}
129
85
  </Box>
130
86
  );
131
87
  };
@@ -133,54 +89,11 @@ export const Background = () => {
133
89
  export const Border = () => {
134
90
  return (
135
91
  <Box gap="md">
136
- <Box borderColor="default" borderWidth="sm" padding="md">
137
- default
138
- </Box>
139
- <Box borderColor="subtle" borderWidth="sm" padding="md">
140
- subtle
141
- </Box>
142
- <Box borderColor="hover" borderWidth="sm" padding="md">
143
- hover
144
- </Box>
145
- <Box borderColor="active" borderWidth="sm" padding="md">
146
- active
147
- </Box>
148
- <Box borderColor="info" borderWidth="sm" padding="md">
149
- info
150
- </Box>
151
- <Box borderColor="warning" borderWidth="sm" padding="md">
152
- warning
153
- </Box>
154
- <Box borderColor="danger" borderWidth="sm" padding="md">
155
- danger
156
- </Box>
157
- <Box borderColor="brand-yellow" borderWidth="sm" padding="md">
158
- brand-yellow
159
- </Box>
160
- <Box borderColor="brand-orange" borderWidth="sm" padding="md">
161
- brand-orange
162
- </Box>
163
- <Box borderColor="brand-magenta" borderWidth="sm" padding="md">
164
- brand-magenta
165
- </Box>
166
- <Box borderColor="brand-dark-grey" borderWidth="sm" padding="md">
167
- brand-dark-grey
168
- </Box>
169
- <Box borderColor="brand-cyan" borderWidth="sm" padding="md">
170
- brand-cyan
171
- </Box>
172
- <Box borderColor="brand-pink" borderWidth="sm" padding="md">
173
- brand-pink
174
- </Box>
175
- <Box borderColor="brand-light-purple" borderWidth="sm" padding="md">
176
- brand-light-purple
177
- </Box>
178
- <Box borderColor="brand-medium-purple" borderWidth="sm" padding="md">
179
- brand-medium-purple
180
- </Box>
181
- <Box borderColor="brand-dark-purple" borderWidth="sm" padding="md">
182
- brand-dark-purple
183
- </Box>
92
+ {BORDER_COLOR_OPTIONS.map((color) => (
93
+ <Box key={color} borderColor={color} borderWidth="sm" padding="md">
94
+ {color}
95
+ </Box>
96
+ ))}
184
97
  </Box>
185
98
  );
186
99
  };
@@ -703,23 +616,11 @@ export const FlexAlignContent = () => (
703
616
 
704
617
  export const FontColor = () => (
705
618
  <>
706
- <Box color="base">base</Box>
707
- <Box color="secondary">secondary</Box>
708
- <Box color="tertiary">tertiary</Box>
709
- <Box color="inverse">inverse</Box>
710
- <Box color="disabled">disabled</Box>
711
- <Box color="success">success</Box>
712
- <Box color="warning">warn</Box>
713
- <Box color="danger">danger</Box>
714
- <Box color="brand-yellow">brand-yellow</Box>
715
- <Box color="brand-orange">brand-orange</Box>
716
- <Box color="brand-magenta">brand-magenta</Box>
717
- <Box color="brand-dark-grey">brand-dark-grey</Box>
718
- <Box color="brand-cyan">brand-cyan</Box>
719
- <Box color="brand-pink">brand-pink</Box>
720
- <Box color="brand-light-purple">brand-light-purple</Box>
721
- <Box color="brand-medium-purple">brand-medium-purple</Box>
722
- <Box color="brand-dark-purple">brand-dark-purple</Box>
619
+ {FONT_COLOR_OPTIONS.map((color) => (
620
+ <Box key={color} color={color}>
621
+ {color}
622
+ </Box>
623
+ ))}
723
624
  </>
724
625
  );
725
626
 
@@ -49,6 +49,13 @@ import { getDimensionCss } from '../../lib/getDimensionCss';
49
49
  import { getElementType } from '../../lib/getElementType';
50
50
  import styles from './Box.module.scss';
51
51
 
52
+ const AUTO_FONT_COLOR_BACKGROUNDS: BackgroundColor[] = [
53
+ 'success',
54
+ 'warning',
55
+ 'danger',
56
+ 'info',
57
+ ];
58
+
52
59
  export type HoverableBoxProperties =
53
60
  | 'color'
54
61
  | 'borderColor'
@@ -355,6 +362,17 @@ export const Box: FC<BoxProps> = forwardRef(
355
362
  const minHeightCss = getDimensionCss('minh', minHeight);
356
363
  const minWidthCss = getDimensionCss('minw', minWidth);
357
364
 
365
+ // `inverse` background uses a matching `inverse` font color instead of the
366
+ // generic auto-mapped colors in AUTO_FONT_COLOR_BACKGROUNDS, so it is
367
+ // intentionally handled separately here.
368
+ const finalColor =
369
+ color ??
370
+ (background === 'inverse'
371
+ ? 'inverse'
372
+ : AUTO_FONT_COLOR_BACKGROUNDS.includes(background)
373
+ ? 'grey'
374
+ : undefined);
375
+
358
376
  const isFlexBox = typeof display === 'string' && display.includes('flex');
359
377
  const flexDirectionClasses = isFlexBox
360
378
  ? generateResponsiveClasses('flex-direction', direction)
@@ -451,7 +469,7 @@ export const Box: FC<BoxProps> = forwardRef(
451
469
  'flex-wrap': isFlexBox && wrap,
452
470
  'flex-nowrap': isFlexBox && wrap === false,
453
471
  [`background-color-${background}`]: background,
454
- [`font-color-${color}`]: color,
472
+ [`font-color-${finalColor}`]: finalColor,
455
473
  [`border-color-${borderColor}`]: borderColor,
456
474
  [`cursor-${cursor}`]: cursor,
457
475
  [styles['box-transition']]: hover || focus,
@@ -42,6 +42,7 @@ export const FormikForm = () =>
42
42
  { value: 'chocolate', label: 'Chocolate' },
43
43
  { value: 'strawberry', label: 'Strawberry' },
44
44
  { value: 'vanilla', label: 'Vanilla' },
45
+ { value: 'mint', label: 'Mint', disabled: true },
45
46
  ];
46
47
  const colorOptions = [
47
48
  { value: 'red', label: 'red' },
@@ -18,6 +18,7 @@ const options = [
18
18
  { value: 'chocolate', label: 'Chocolate' },
19
19
  { value: 'strawberry', label: 'Strawberry' },
20
20
  { value: 'vanilla', label: 'Vanilla' },
21
+ { value: 'mint', label: 'Mint', disabled: true },
21
22
  ];
22
23
 
23
24
  export const Default = () => {
@@ -5,9 +5,23 @@ import { SelectInputNative } from './SelectInputNative';
5
5
 
6
6
  const selectOptions = [
7
7
  { value: 'chocolate', label: 'Chocolate' },
8
- { value: 'strawberry', label: 'Strawberry' },
8
+ { value: 'strawberry', label: 'Strawberry', disabled: true },
9
9
  { value: 'vanilla', label: 'Vanilla' },
10
10
  ];
11
+ test('option with disabled property is rendered as disabled', () => {
12
+ const mockedHandleChange = jest.fn();
13
+ render(
14
+ <SelectInputNative
15
+ id="testId"
16
+ label="Disabled Option Test"
17
+ onChange={mockedHandleChange}
18
+ options={selectOptions}
19
+ value={null}
20
+ />
21
+ );
22
+ const option = screen.getByText('Strawberry');
23
+ expect(option).toBeDisabled();
24
+ });
11
25
 
12
26
  function getByTextWithMarkup(text: string) {
13
27
  // eslint-disable-next-line
@@ -7,11 +7,17 @@ import { FormControl, FormControlProps } from '../FormControl/FormControl';
7
7
  import styles from './SelectInputNative.module.scss';
8
8
 
9
9
  export type SelectInputNativeSize = 'sm' | 'md' | 'lg';
10
+ export interface SelectInputNativeOption {
11
+ value: string | number;
12
+ label: string | number;
13
+ disabled?: boolean;
14
+ }
15
+
10
16
  export interface SelectInputNativeProps extends BoxProps, FormControlProps {
11
17
  /**
12
18
  * List of options for the select input.
13
19
  */
14
- options: { value: string | number; label: string | number }[];
20
+ options: SelectInputNativeOption[];
15
21
  /**
16
22
  * onChange callback from select element.
17
23
  */
@@ -60,8 +66,15 @@ export const SelectInputNative: React.FC<SelectInputNativeProps> = ({
60
66
  size = 'md',
61
67
  ...restProps
62
68
  }) => {
63
- const placeholderOption = { value: '', label: placeholder };
64
- const optionsWithPlaceholder = [{ ...placeholderOption }, ...options];
69
+ const placeholderOption: SelectInputNativeOption = {
70
+ value: '',
71
+ label: placeholder,
72
+ disabled: true,
73
+ };
74
+ const optionsWithPlaceholder: SelectInputNativeOption[] = [
75
+ placeholderOption,
76
+ ...options,
77
+ ];
65
78
 
66
79
  const responsiveClasses = generateResponsiveClasses('size', size);
67
80
 
@@ -107,7 +120,7 @@ export const SelectInputNative: React.FC<SelectInputNativeProps> = ({
107
120
  as="option"
108
121
  key={option.value}
109
122
  value={option.value}
110
- disabled={option.value === ''}
123
+ disabled={option.disabled ?? false}
111
124
  hidden={option.value === ''}
112
125
  color={option.value === '' ? 'disabled' : 'base'}
113
126
  >
@@ -156,22 +156,17 @@ const data = {
156
156
  ],
157
157
  };
158
158
 
159
- // type Story = StoryObj<typeof Sidebar>;
160
-
161
159
  export const SidebarExample = () => {
162
160
  const [activeTeam, setActiveTeam] = React.useState(data.teams[0]);
163
161
  const isMobile = useIsMobile();
164
162
 
165
163
  const STORAGE_KEY = 'sidebar_expanded_storybook';
166
164
 
167
- const startOpen = localStorage.getItem(STORAGE_KEY) || 'true';
165
+ const startExpanded = localStorage.getItem(STORAGE_KEY) !== 'false';
168
166
 
169
167
  return (
170
168
  <ResponsiveProvider>
171
- <SidebarProvider
172
- storageKey={STORAGE_KEY}
173
- defaultOpen={startOpen === 'true'}
174
- >
169
+ <SidebarProvider storageKey={STORAGE_KEY} defaultOpen={startExpanded}>
175
170
  <Sidebar side="left" collapsible="icon">
176
171
  <NavHeader activeTeam={activeTeam} setActiveTeam={setActiveTeam} />
177
172
  <SidebarContent>