@nuskin/foundation-ui-components 1.0.0-develop.3 → 1.0.0-develop.4

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 (76) hide show
  1. package/package.json +1 -1
  2. package/src/common/accordion/NsAccordion.tsx +77 -0
  3. package/src/common/accordion/NsAccordionHeader.tsx +56 -0
  4. package/src/common/accordion/NsAccordionItem.tsx +39 -0
  5. package/src/common/accordion/NsCollapse.tsx +56 -0
  6. package/src/common/accordion/NsToggleSection.tsx +30 -0
  7. package/src/common/accordion/ToggleSection.styled.tsx +28 -0
  8. package/src/common/accordion/index.ts +6 -0
  9. package/src/common/accordion/specs/NsAccordion.spec.tsx +91 -0
  10. package/src/common/accordion/specs/NsAccordionHeader.spec.tsx +47 -0
  11. package/src/common/accordion/specs/NsAccordionItem.spec.tsx +38 -0
  12. package/src/common/accordion/specs/NsCollapse.spec.tsx +37 -0
  13. package/src/common/accordion/specs/NsToggleSection.spec.tsx +33 -0
  14. package/src/common/accordion/stories/NsAccordion.stories.tsx +47 -0
  15. package/src/common/accordion/stories/NsAccordionHeader.stories.tsx +40 -0
  16. package/src/common/accordion/stories/NsAccordionItem.stories.tsx +40 -0
  17. package/src/common/accordion/stories/NsCollapse.stories.tsx +35 -0
  18. package/src/common/accordion/stories/NsToggleSection.stories.tsx +23 -0
  19. package/src/common/accordion/stories/data.tsx +22 -0
  20. package/src/common/accordion/types.d.ts +73 -0
  21. package/src/common/alert/types.d.ts +22 -22
  22. package/src/common/autocomplete/NsAutocomplete.spec.tsx +20 -8
  23. package/src/common/autocomplete/NsAutocomplete.stories.tsx +3 -0
  24. package/src/common/autocomplete/NsAutocomplete.styled.tsx +12 -0
  25. package/src/common/autocomplete/NsAutocomplete.tsx +36 -18
  26. package/src/common/autocomplete/types.d.ts +7 -1
  27. package/src/common/button/NsButton.spec.tsx +10 -11
  28. package/src/common/checkbox/NsCheckbox.styled.tsx +2 -2
  29. package/src/common/common.types.d.ts +1 -0
  30. package/src/common/email-simple/NsEmailSimple.spec.tsx +145 -0
  31. package/src/common/email-simple/NsEmailSimple.stories.tsx +61 -0
  32. package/src/common/email-simple/NsEmailSimple.tsx +71 -0
  33. package/src/common/email-simple/index.ts +2 -0
  34. package/src/common/email-simple/types.d.ts +14 -0
  35. package/src/common/flag/NsFlag.spec.tsx +4 -25
  36. package/src/common/flag/NsFlag.tsx +0 -2
  37. package/src/common/image/types.d.ts +1 -0
  38. package/src/common/index.ts +3 -0
  39. package/src/common/input/NsInputField.stories.tsx +11 -9
  40. package/src/common/input/NsInputField.tsx +12 -5
  41. package/src/common/input/getAdornmentProps.tsx +4 -0
  42. package/src/common/input/types.d.ts +3 -1
  43. package/src/common/label/NsLabel.stories.tsx +3 -0
  44. package/src/common/label/NsLabel.tsx +14 -17
  45. package/src/common/label/types.d.ts +2 -1
  46. package/src/common/nav-tab/NsNavTab.spec.tsx +0 -5
  47. package/src/common/radiogroup/NsRadioGroup.spec.tsx +63 -0
  48. package/src/common/radiogroup/NsRadioGroup.stories.tsx +101 -0
  49. package/src/common/radiogroup/NsRadioGroup.styled.tsx +56 -0
  50. package/src/common/radiogroup/NsRadioGroup.tsx +46 -0
  51. package/src/common/radiogroup/index.ts +2 -0
  52. package/src/common/radiogroup/types.d.ts +19 -0
  53. package/src/common/select/NsSelect.spec.tsx +200 -0
  54. package/src/common/select/NsSelect.styled.tsx +89 -0
  55. package/src/common/select/NsSelect.tsx +117 -0
  56. package/src/common/select/NsSelectOption.tsx +30 -0
  57. package/src/common/select/index.ts +3 -0
  58. package/src/common/select/stories/NsSelect.stories.tsx +134 -0
  59. package/src/common/select/types.d.ts +34 -0
  60. package/src/common/table/NsExpandableRow.tsx +68 -0
  61. package/src/common/table/NsTable.spec.tsx +69 -41
  62. package/src/common/table/NsTable.stories.tsx +45 -7
  63. package/src/common/table/NsTable.styled.ts +95 -4
  64. package/src/common/table/NsTable.tsx +78 -89
  65. package/src/common/table/NsTableHeader.tsx +52 -38
  66. package/src/common/table/NsTablePagination.tsx +21 -13
  67. package/src/common/table/types.d.ts +21 -8
  68. package/src/common/validations/regex.ts +3 -0
  69. /package/src/common/card/{tests → specs}/BrandLogo.spec.tsx +0 -0
  70. /package/src/common/card/{tests → specs}/NsBgCard.spec.tsx +0 -0
  71. /package/src/common/card/{tests → specs}/NsBrandProductCard.spec.tsx +0 -0
  72. /package/src/common/card/{tests → specs}/NsFfgCard.spec.tsx +0 -0
  73. /package/src/common/carousal/{tests → specs}/Chevron.spec.tsx +0 -0
  74. /package/src/common/carousal/{tests → specs}/NsCarousal.spec.tsx +0 -0
  75. /package/src/common/carousal/{tests → specs}/NsScrollingCarousal.spec.tsx +0 -0
  76. /package/src/common/carousal/{tests → specs}/RenderBrand.spec.tsx +0 -0
@@ -0,0 +1,145 @@
1
+ import React from 'react';
2
+ import { render, screen, act } from '@testing-library/react';
3
+ import NsEmailSimple from './NsEmailSimple';
4
+ import { userEvent } from '@storybook/testing-library';
5
+ import { emailPattern } from '../validations/regex';
6
+
7
+ describe('NsEmailSimple', () => {
8
+ let mockCheckEmail = jest.fn().mockResolvedValue([true, false]);
9
+ let propsData = {
10
+ disabled: false,
11
+ label: 'Email',
12
+ required: true,
13
+ maxLength: 50,
14
+ invalidEmailMessage: 'Please enter a valid email',
15
+ dupedEmailMessage: 'Email ID already exists',
16
+ requiredErrorMessage: 'Email field is required',
17
+ checkEmail: mockCheckEmail,
18
+ };
19
+ it('renders email field with invalid regex error', async () => {
20
+ render(<NsEmailSimple {...propsData} />);
21
+ const emailField = (await screen.findByTestId('email-field-test')) as HTMLInputElement;
22
+ expect(emailField).toBeInTheDocument;
23
+ const inputElement = emailField.querySelector('input');
24
+ if (!inputElement) {
25
+ return;
26
+ }
27
+ act(() => {
28
+ userEvent.type(inputElement, 'test');
29
+ userEvent.tab();
30
+ });
31
+
32
+ expect(inputElement).toHaveValue('test');
33
+
34
+ act(() => {
35
+ userEvent.clear(inputElement);
36
+ userEvent.type(inputElement, 'test@gm');
37
+ userEvent.tab();
38
+ });
39
+ expect(inputElement).toHaveValue('test@gm');
40
+
41
+ mockCheckEmail = jest.fn().mockResolvedValue([true, true]);
42
+ render(<NsEmailSimple {...propsData} />);
43
+ act(() => {
44
+ userEvent.clear(inputElement);
45
+ userEvent.type(inputElement, 'test!gmail');
46
+ userEvent.tab();
47
+ });
48
+ expect(inputElement).toHaveValue('test!gmail');
49
+ act(() => {
50
+ userEvent.clear(inputElement);
51
+ userEvent.tab();
52
+ });
53
+ expect(inputElement).toHaveValue('');
54
+
55
+ mockCheckEmail = jest.fn().mockResolvedValue([true, false]);
56
+ render(<NsEmailSimple {...propsData} />);
57
+ act(() => {
58
+ userEvent.clear(inputElement);
59
+ userEvent.type(inputElement, 'test@gmail.co');
60
+ userEvent.tab();
61
+ });
62
+ expect(inputElement).toHaveValue('test@gmail.co');
63
+ });
64
+ it('renders email field with invalid error', async () => {
65
+ let mockCheckEmail1 = jest.fn().mockResolvedValue([false, false]);
66
+ let propsData1 = {
67
+ disabled: false,
68
+ label: 'Email',
69
+ required: true,
70
+ maxLength: 50,
71
+ invalidEmailMessage: 'Please enter a valid email',
72
+ dupedEmailMessage: 'Email ID already exists',
73
+ requiredErrorMessage: 'Email field is required',
74
+ checkEmail: mockCheckEmail1,
75
+ };
76
+ render(<NsEmailSimple {...propsData1} />);
77
+ const emailField = (await screen.findByTestId('email-field-test')) as HTMLInputElement;
78
+ expect(emailField).toBeInTheDocument;
79
+ const inputElement = emailField.querySelector('input');
80
+ if (!inputElement) {
81
+ return;
82
+ }
83
+ act(() => {
84
+ userEvent.clear(inputElement);
85
+ userEvent.type(inputElement, 'test@gmail.com');
86
+ userEvent.tab();
87
+ });
88
+ expect(inputElement).toHaveValue('test@gmail.com');
89
+ expect(inputElement.value).toMatch(emailPattern);
90
+ });
91
+ it('renders email field without error', async () => {
92
+ let mockCheckEmail1 = jest.fn().mockResolvedValue([true, true]);
93
+ let propsData1 = {
94
+ disabled: false,
95
+ label: 'Email',
96
+ required: true,
97
+ maxLength: 50,
98
+ invalidEmailMessage: 'Please enter a valid email',
99
+ dupedEmailMessage: 'Email ID already exists',
100
+ requiredErrorMessage: 'Email field is required',
101
+ checkEmail: mockCheckEmail1,
102
+ };
103
+ render(<NsEmailSimple {...propsData1} />);
104
+ const emailField = (await screen.findByTestId('email-field-test')) as HTMLInputElement;
105
+ expect(emailField).toBeInTheDocument;
106
+ const inputElement = emailField.querySelector('input');
107
+ if (!inputElement) {
108
+ return;
109
+ }
110
+ act(() => {
111
+ userEvent.clear(inputElement);
112
+ userEvent.type(inputElement, 'test@gmail.com');
113
+ userEvent.tab();
114
+ });
115
+ expect(inputElement).toHaveValue('test@gmail.com');
116
+ expect(inputElement.value).toMatch(emailPattern);
117
+ });
118
+ it('renders email field with API error', async () => {
119
+ let mockCheckEmail1 = jest.fn().mockResolvedValue(undefined);
120
+ let propsData1 = {
121
+ disabled: false,
122
+ label: 'Email',
123
+ required: true,
124
+ maxLength: 50,
125
+ invalidEmailMessage: 'Please enter a valid email',
126
+ dupedEmailMessage: 'Email ID already exists',
127
+ requiredErrorMessage: 'Email field is required',
128
+ checkEmail: mockCheckEmail1,
129
+ };
130
+ render(<NsEmailSimple {...propsData1} />);
131
+ const emailField = (await screen.findByTestId('email-field-test')) as HTMLInputElement;
132
+ expect(emailField).toBeInTheDocument;
133
+ const inputElement = emailField.querySelector('input');
134
+ if (!inputElement) {
135
+ return;
136
+ }
137
+ act(() => {
138
+ userEvent.clear(inputElement);
139
+ userEvent.type(inputElement, 'test@gmail.com');
140
+ userEvent.tab();
141
+ });
142
+ expect(inputElement).toHaveValue('test@gmail.com');
143
+ expect(inputElement.value).toMatch(emailPattern);
144
+ });
145
+ });
@@ -0,0 +1,61 @@
1
+ import type { StoryObj, Meta } from '@storybook/react';
2
+ import NsEmailSimple from './NsEmailSimple';
3
+ import { within } from '@storybook/testing-library';
4
+ import { expect } from '@storybook/jest';
5
+ import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
6
+
7
+ async function checkEmail() {
8
+ const isServiceValid = Promise.resolve(true);
9
+ const isEmailAvailable = Promise.resolve(true);
10
+ return [isServiceValid, isEmailAvailable];
11
+ }
12
+ type ComponentType = typeof NsEmailSimple;
13
+ type Story = StoryObj<ComponentType>;
14
+ type MetaStory = Meta<ComponentType>;
15
+
16
+ export default {
17
+ component: NsEmailSimple,
18
+ title: 'Components/Inputs/NsEmailSimple',
19
+ decorators: [withCenterDecorator],
20
+ play: ({ canvasElement }) => {
21
+ const canvas = within(canvasElement);
22
+ const el = canvas.getByTestId('email-field-test');
23
+ expect(el).toBeInTheDocument();
24
+ },
25
+
26
+ argTypes: {
27
+ disabled: {
28
+ description: 'Indicates whether the email field is enabled/disabled',
29
+ },
30
+ label: {
31
+ description: 'Label of the email component',
32
+ },
33
+ required: {
34
+ description: 'Indicates whether the email field is mandatory or not',
35
+ },
36
+ maxLength: {
37
+ description: 'Maximum number of characters allowed',
38
+ },
39
+ invalidEmailMessage: {
40
+ description: 'Displayed when an invalid email is entered',
41
+ },
42
+ dupedEmailMessage: {
43
+ description: 'Displayed when a duplicate email is entered',
44
+ },
45
+ requiredErrorMessage: {
46
+ description: 'Displayed when email is not entered',
47
+ },
48
+ },
49
+ args: {
50
+ disabled: false,
51
+ label: 'Email',
52
+ required: true,
53
+ maxLength: 50,
54
+ invalidEmailMessage: 'Please enter a valid email',
55
+ dupedEmailMessage: 'Email ID already exists',
56
+ requiredErrorMessage: 'Email field is required',
57
+ checkEmail: checkEmail,
58
+ },
59
+ } as MetaStory;
60
+
61
+ export const NsEmail: Story = {};
@@ -0,0 +1,71 @@
1
+ import React, { useState } from 'react';
2
+ import { NsEmailSimpleProps } from './types';
3
+ import { NsInputField } from '../input';
4
+ import { fieldStateType } from '../input/types';
5
+ import { emailPattern } from '../validations/regex';
6
+
7
+ const NsEmailSimple = (props: NsEmailSimpleProps) => {
8
+ const {
9
+ disabled,
10
+ label,
11
+ required,
12
+ maxLength,
13
+ invalidEmailMessage,
14
+ dupedEmailMessage,
15
+ requiredErrorMessage,
16
+ checkEmail,
17
+ additionalProps,
18
+ } = props;
19
+ const [fieldState, setFieldState] = useState<fieldStateType>();
20
+ const [errorMsg, setErrorMessage] = useState('');
21
+
22
+ const handleBlur = async (e: React.FocusEvent<HTMLInputElement>) => {
23
+ const emailInput = e.target.value.toLowerCase().trim();
24
+ let fieldStateValue: fieldStateType;
25
+ let errorMessageValue = '';
26
+ if (required && !emailInput) {
27
+ fieldStateValue = 'error';
28
+ errorMessageValue = requiredErrorMessage;
29
+ } else if (!emailPattern.test(emailInput)) {
30
+ fieldStateValue = 'error';
31
+ errorMessageValue = invalidEmailMessage;
32
+ } else if (typeof checkEmail === 'function') {
33
+ try {
34
+ const [isValid, isAvailable] = await checkEmail();
35
+ if (!isValid) {
36
+ fieldStateValue = 'error';
37
+ errorMessageValue = invalidEmailMessage;
38
+ } else if (!isAvailable) {
39
+ fieldStateValue = 'error';
40
+ errorMessageValue = dupedEmailMessage;
41
+ } else {
42
+ fieldStateValue = undefined;
43
+ errorMessageValue = '';
44
+ }
45
+ } catch (error) {
46
+ console.log('API error', error);
47
+ }
48
+ } else {
49
+ //TODO What happens when user does not pass valid checkEmail function
50
+ }
51
+ setFieldState(fieldStateValue);
52
+ setErrorMessage(errorMessageValue);
53
+ };
54
+ return (
55
+ <NsInputField
56
+ required={required}
57
+ disabled={disabled}
58
+ label={label}
59
+ onBlur={handleBlur}
60
+ inputProps={{ maxLength }}
61
+ additionalProps={{ testid: additionalProps?.testid ?? 'email-field-test' }}
62
+ helperText={errorMsg}
63
+ fieldState={fieldState}
64
+ InputProps={{
65
+ endAdornment: null,
66
+ }}
67
+ />
68
+ );
69
+ };
70
+
71
+ export default NsEmailSimple;
@@ -0,0 +1,2 @@
1
+ export { default as NsEmailSimple } from './NsEmailSimple';
2
+ export type { NsEmailSimpleProps } from './types.d';
@@ -0,0 +1,14 @@
1
+ import { TextFieldProps } from '@mui/material';
2
+ import { AdditionalProps } from '../common.types';
3
+
4
+ export type NsEmailSimpleProps = Pick<TextFieldProps> &
5
+ AdditionalProps & {
6
+ disabled?: boolean;
7
+ label?: string;
8
+ required?: boolean;
9
+ maxLength?: number;
10
+ invalidEmailText?: string;
11
+ dupedEmailText?: string;
12
+ requiredErrorMessage?: string;
13
+ checkEmail?: Function;
14
+ };
@@ -1,35 +1,14 @@
1
- /**
2
- * @author [vijayaprathap Kumar] (vpkumar@nuskin.com)
3
- * Flag.spec.tsx
4
- * @description In this test case,
5
- * we use the render function to render the MyComponent with the desired background color and text.
6
- */
7
-
8
1
  import React from 'react';
9
- import nuskinTheme from '@nuskin/foundation-theme/src/themes/genome-foundation';
10
-
11
2
  import { render } from '@/test-utils/index';
12
- import NsFlag from './NsFlag';
13
-
14
- const { palette } = nuskinTheme;
3
+ import { NsFlag } from '../';
15
4
 
16
- // Test suite for FlagComponent
17
5
  describe('FlagComponent', () => {
18
- // Test case for rendering a div element with background color and text.
19
6
  it('renders a div element with background color and text', () => {
20
- // Render FlagComponent with blue background color and "Nuskin" text
7
+ const text = 'NU SKIN';
21
8
  const { getByText } = render(<NsFlag message="NU SKIN" color="accentColorA" />);
9
+ const divElement = getByText(text);
22
10
 
23
- // Get the rendered div element using its text
24
- const divElement = getByText('NU SKIN');
25
-
26
- // Assert that the div element is in the document
27
11
  expect(divElement).toBeInTheDocument();
28
-
29
- // Assert that the div element has the expected background color
30
- expect(divElement).toHaveStyle(`color: ${palette?.primary?.contrastText}`);
31
-
32
- // Assert that the div element has the expected text content
33
- expect(divElement).toHaveTextContent('NU SKIN');
12
+ expect(divElement).toHaveTextContent(text);
34
13
  });
35
14
  });
@@ -5,9 +5,7 @@
5
5
  */
6
6
 
7
7
  import React, { PropsWithChildren } from 'react';
8
-
9
8
  import { StyledFlag } from './NsFlag.styled';
10
-
11
9
  import { NsFlagProps } from './types.d';
12
10
 
13
11
  const NsFlag = (props: PropsWithChildren<NsFlagProps>) => {
@@ -15,6 +15,7 @@ export type NsNextImageProps = Pick<
15
15
  | 'blurDataURL'
16
16
  | 'fill'
17
17
  | 'unoptimized'
18
+ | 'loader'
18
19
  > & { id?: string; className?: string };
19
20
 
20
21
  export type NsImageProps = {
@@ -1,3 +1,4 @@
1
+ export * from './accordion';
1
2
  export * from './alert';
2
3
  export * from './auth-dropdown';
3
4
  export * from './autocomplete';
@@ -23,3 +24,5 @@ export * from './nav-product-card';
23
24
  export * from './text-strip';
24
25
  export * from './table';
25
26
  export * from './typography';
27
+ export * from './email-simple';
28
+ export * from './radiogroup';
@@ -8,31 +8,33 @@ type Story = StoryObj<ComponentType>;
8
8
  type MetaStory = Meta<ComponentType>;
9
9
 
10
10
  export default {
11
- title: 'Components/NsInputField',
11
+ title: 'Components/Inputs/NsInputField',
12
12
  component: NsInputField,
13
13
  decorators: [withCenterDecorator],
14
-
15
- args: {},
14
+ args: {
15
+ helperText: '',
16
+ iconSide: <NsIcon name="trash" />,
17
+ focused: false,
18
+ placeholder: 'enter text',
19
+ disabled: false,
20
+ fullWidth: false,
21
+ },
16
22
  argTypes: {
17
23
  fieldState: { control: 'select', options: ['default', 'success', 'error'] },
18
24
  value: { control: 'text' },
25
+ helperText: { control: 'text', description: 'text shown below input' },
19
26
  required: { control: 'boolean' },
20
27
  disabled: { control: 'boolean' },
21
28
  fullWidth: { control: 'boolean' },
22
- showOptional: { control: 'boolean' },
29
+ showOptional: { control: 'boolean', description: 'if true, an optional text is shown along with label' },
23
30
  focused: { control: 'boolean' },
24
31
  },
25
32
  } as MetaStory;
26
33
 
27
34
  export const Default: Story = {
28
35
  args: {
29
- focused: false,
30
- placeholder: 'enter text',
31
- disabled: false,
32
- fullWidth: false,
33
36
  value: 'Input value',
34
37
  fieldState: 'success',
35
- iconSide: <NsIcon name="trash" />,
36
38
  },
37
39
  };
38
40
 
@@ -3,7 +3,7 @@ import InputWrapper from './InputWrapper';
3
3
  import { NsInputFieldProps } from './types.d';
4
4
  import { NsLabel } from '../label';
5
5
  import InputFieldWrapper from './InputFieldWrapper';
6
- import { getAdornmentProps } from './getAdornmentProps';
6
+ import { AdornmentPropsType, getAdornmentProps } from './getAdornmentProps';
7
7
 
8
8
  /**
9
9
  * we are using fieldState in place of error prop
@@ -14,6 +14,7 @@ const NsInputField = (props: NsInputFieldProps) => {
14
14
  const {
15
15
  autoComplete,
16
16
  autoFocus,
17
+ additionalProps,
17
18
  defaultValue,
18
19
  disabled,
19
20
  fullWidth,
@@ -54,16 +55,22 @@ const NsInputField = (props: NsInputFieldProps) => {
54
55
  } = props;
55
56
  /** EndIcon is created so that we can automatically add success and error icon based of fieldState,
56
57
  * it will override iconEnd. Also to note, InputProps is given to override both iconStart, iconEnd and EndIcon */
57
- let EndIcon: any = getAdornmentProps({ disabled, fieldState, iconEnd, iconStart });
58
+ let EndIcon: AdornmentPropsType = getAdornmentProps({ disabled, fieldState, iconEnd, iconStart });
58
59
 
59
60
  return (
60
61
  <InputFieldWrapper>
61
62
  {label ? (
62
- <NsLabel {...InputLabelProps} showOptional={showOptional} required={required} disabled={disabled}>
63
+ <NsLabel
64
+ {...InputLabelProps}
65
+ showOptional={showOptional}
66
+ required={required}
67
+ disabled={disabled}
68
+ error={fieldState === 'error' && !disabled}
69
+ >
63
70
  {label}
64
71
  </NsLabel>
65
72
  ) : null}
66
- <InputWrapper fieldState={fieldState} data-testid="ns-input-field">
73
+ <InputWrapper fieldState={fieldState} data-testid={additionalProps?.testid ?? 'ns-input-field'}>
67
74
  <TextField
68
75
  {...rest}
69
76
  InputProps={{
@@ -97,7 +104,7 @@ const NsInputField = (props: NsInputFieldProps) => {
97
104
  />
98
105
  {iconSide}
99
106
  </InputWrapper>
100
- {helperText ? (
107
+ {helperText && !disabled ? (
101
108
  <FormHelperText {...FormHelperTextProps} className={fieldState}>
102
109
  {helperText}
103
110
  </FormHelperText>
@@ -22,6 +22,10 @@ type props = {
22
22
  * @param param0
23
23
  * @returns
24
24
  */
25
+ export type AdornmentPropsType = {
26
+ startAdornment?: ReactNode;
27
+ endAdornment?: ReactNode;
28
+ }
25
29
  export const getAdornmentProps = ({ disabled, fieldState, iconStart, iconEnd }: props) => {
26
30
  const icons = {
27
31
  startAdornment: iconStart ? <InputAdornment position="start">{iconStart}</InputAdornment> : null,
@@ -1,6 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { TextFieldProps } from '@mui/material';
3
+ import { AdditionalProps } from '../common.types';
3
4
 
5
+ // TODO: check if fieldStateType could be converted to enum, since we also have to account for undefined
4
6
  export type fieldStateType = undefined | 'error' | 'success';
5
7
  export type NsInputFieldProps = Omit<
6
8
  TextFieldProps,
@@ -39,4 +41,4 @@ export type NsInputFieldProps = Omit<
39
41
  defaultValue?: string;
40
42
  rows?: number;
41
43
  id?: string;
42
- };
44
+ } & AdditionalProps;
@@ -16,6 +16,7 @@ export const Default: Story = {
16
16
  args: {
17
17
  children: 'Label',
18
18
  required: false,
19
+ size: 16,
19
20
  },
20
21
  };
21
22
 
@@ -23,6 +24,7 @@ export const Optional: Story = {
23
24
  args: {
24
25
  children: 'Label',
25
26
  showOptional: true,
27
+ size: 16,
26
28
  },
27
29
  };
28
30
 
@@ -31,5 +33,6 @@ export const Required: Story = {
31
33
  children: 'Label',
32
34
  showOptional: true,
33
35
  required: true,
36
+ size: 16,
34
37
  },
35
38
  };
@@ -1,33 +1,30 @@
1
1
  import { FormLabel } from '@mui/material';
2
2
  import { NsLabelProps } from './types.d';
3
- import { styled, nuskinTheme } from '@nuskin/foundation-theme';
3
+ import { styled, ColorUtils } from '@nuskin/foundation-theme';
4
+ import { CSSProperties } from 'react';
5
+ const { getAppColor, getPaletteColor } = ColorUtils;
4
6
 
5
- const { colors } = nuskinTheme;
6
-
7
- const StyledLabel = styled(FormLabel)<{ fontSize?: number }>(({ theme, fontSize }) => {
7
+ const StyledLabel = styled(FormLabel)<{ fontSize?: number; style?: CSSProperties }>(({ theme, fontSize, style }) => {
8
8
  const isLight = theme.palette?.primary?.main === '#252525';
9
9
  return {
10
10
  fontSize: fontSize ? `${fontSize}px` : '14px',
11
- color: theme.palette?.primary?.main ?? '#252525',
11
+ textAlign: style?.textAlign ?? 'left',
12
+ color: getPaletteColor(theme, 'primary', 'main'),
12
13
  '.optional-label': {
13
- color: isLight ? colors?.neutral?.[60] : colors?.neutral?.[50],
14
+ color: isLight ? getAppColor(theme, 'neutral', '60') : getAppColor(theme, 'neutral', '50'),
14
15
  },
15
16
  '.MuiInputLabel-asterisk': {
16
- color: isLight ? colors?.red?.[40] : colors?.red?.[20],
17
+ color: isLight ? getAppColor(theme, 'error', '40') : getAppColor(theme, 'error', '20'),
17
18
  },
18
- };
19
+ ...(style || {}),
20
+ } as any; // TODO: may be this "any" has to be fixed from foundation-theme
19
21
  });
20
- /**
21
- * NOTE: we are passing error = false, in props, because
22
- * we do not want to change the color of label to red, in case of error
23
- * @param props
24
- * @returns
25
- */
22
+
26
23
  const NsLabel = (props: NsLabelProps) => {
27
- const { required, showOptional } = props;
24
+ const { required, showOptional, children, size } = props;
28
25
  return (
29
- <StyledLabel {...props} required={required} error={false}>
30
- {props.children}
26
+ <StyledLabel {...props} fontSize={size} required={required}>
27
+ {children}
31
28
  {!required && showOptional ? <span className="optional-label">{' (Optional)'}</span> : null}
32
29
  </StyledLabel>
33
30
  );
@@ -2,8 +2,9 @@ import { InputLabelProps } from '@mui/material';
2
2
  import { PropsWithChildren } from 'react';
3
3
 
4
4
  export type NsLabelProps = PropsWithChildren &
5
- Omit<InputLabelProps, 'sx' | 'classes' | 'color' | 'margin' | 'variant' | 'classes' | 'error'> & {
5
+ Omit<InputLabelProps, 'sx' | 'classes' | 'color' | 'margin' | 'variant' | 'classes'> & {
6
6
  /** purpose of showOptional props is to show additional text 'optional' in the label,
7
7
  * if required = false and this flag is true */
8
8
  showOptional?: boolean;
9
+ size?: number;
9
10
  };
@@ -1,11 +1,8 @@
1
1
  import { fireEvent } from '@testing-library/react';
2
- import nuskinTheme from '@nuskin/foundation-theme/src/themes/genome-foundation';
3
2
  import { NsNavTabComponent } from './NsNavTab';
4
3
  import { NavTabs } from './types.d';
5
4
  import { render } from '@/test-utils/index';
6
5
 
7
- const { palette } = nuskinTheme;
8
-
9
6
  const tabs: NavTabs[] = [
10
7
  {
11
8
  tabName: 'Skin & Beauty',
@@ -54,7 +51,6 @@ describe('Nav Bar Component', () => {
54
51
  expect(li.length).toBe(4);
55
52
  li.forEach((list, i) => expect(list).toHaveTextContent(tabs[i].tabName));
56
53
  expect(container).toBeInTheDocument();
57
- expect(getByTestId('Skin & Beauty-list').firstChild).toHaveStyle(`color: ${palette.primary.main}`);
58
54
  fireEvent.mouseOver(getByTestId('Skin & Beauty'));
59
55
  expect(getByTestId('nav-drawer')).toBeInTheDocument();
60
56
  fireEvent.mouseLeave(getByTestId('Skin & Beauty'));
@@ -65,6 +61,5 @@ describe('Nav Bar Component', () => {
65
61
  const { getByTestId } = render(<NsNavTabComponent showDrawer={false} className="mb-2" tabs={tabs} />);
66
62
  fireEvent.mouseOver(getByTestId('Skin & Beauty'));
67
63
  expect(getByTestId('underline')).toBeInTheDocument();
68
- expect(getByTestId('underline')).toHaveStyle(`background-color: ${palette.success.main}`);
69
64
  });
70
65
  });
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ import { render, fireEvent, screen } from '@testing-library/react';
3
+ import { NsRadioGroup } from './';
4
+
5
+
6
+ describe('NsRadioGroup', () => {
7
+
8
+ const options = [
9
+ { id: 'Option1', label: 'Option 1', value: 'Option1' },
10
+ { id: 'Option2', label: 'Option 2', value: 'Option2' },
11
+ { id: 'Option3', label: 'Option 3', value: 'Option3' },
12
+ ]
13
+
14
+ const props = {
15
+ disable: false,
16
+ items: options,
17
+ name: 'test',
18
+ label: 'I choose to signup as',
19
+ color: '#272525',
20
+ additionalSlot: 'An additional slot allows for more text',
21
+ size: 24,
22
+ labelFontSize: 16,
23
+ additionalProps: {
24
+ testid: 'radio-group',
25
+ },
26
+ };
27
+ const onChange = jest.fn();
28
+
29
+ it('renders options correctly', () => {
30
+ render(
31
+ <NsRadioGroup {...props} onChange={onChange}
32
+ />,
33
+ );
34
+
35
+ options.forEach((option) => {
36
+ const radioOption = screen.getByLabelText(option.label) as HTMLInputElement;
37
+ expect(radioOption).toBeInTheDocument();
38
+ expect(radioOption.value).toBe(option.value)
39
+ })
40
+
41
+ })
42
+
43
+ it('calls OnChange when selecting option', () => {
44
+
45
+ render(<NsRadioGroup {...props} onChange={onChange} />)
46
+
47
+ const radioOption = screen.getByLabelText('Option 2') as HTMLInputElement
48
+ fireEvent.click(radioOption);
49
+ expect(onChange).toHaveBeenCalledTimes(1);
50
+
51
+ })
52
+
53
+ it('does not call Onchange when the same option is clicked', () => {
54
+ const onChange = jest.fn();
55
+ render(<NsRadioGroup {...props} onChange={onChange} />)
56
+
57
+ const radioOption = screen.getByLabelText('Option 1') as HTMLInputElement
58
+ fireEvent.click(radioOption)
59
+ expect(onChange).not.toHaveBeenCalled();
60
+ })
61
+
62
+
63
+ })