@nuskin/foundation-ui-components 1.0.0-develop.2 → 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 (123) 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/NsAlert.stories.tsx +15 -14
  22. package/src/common/alert/types.d.ts +22 -22
  23. package/src/common/auth-dropdown/NsAuthDropdown.stories.tsx +1 -1
  24. package/src/common/autocomplete/NsAutocomplete.spec.tsx +20 -8
  25. package/src/common/autocomplete/NsAutocomplete.stories.tsx +4 -1
  26. package/src/common/autocomplete/NsAutocomplete.styled.tsx +12 -0
  27. package/src/common/autocomplete/NsAutocomplete.tsx +36 -18
  28. package/src/common/autocomplete/types.d.ts +7 -1
  29. package/src/common/banner/NsBanner.stories.tsx +1 -1
  30. package/src/common/brand-components/NsBrand.stories.tsx +1 -1
  31. package/src/common/breadcrumb/NsBreadcrumb.spec.tsx +1 -7
  32. package/src/common/breadcrumb/NsBreadcrumb.stories.tsx +2 -4
  33. package/src/common/breadcrumb/data.ts +7 -0
  34. package/src/common/button/NsButton.spec.tsx +10 -11
  35. package/src/common/button/NsButton.stories.tsx +1 -1
  36. package/src/common/card/stories/NsBgCard.stories.tsx +1 -3
  37. package/src/common/card/stories/NsBrandProductCard.stories.tsx +1 -1
  38. package/src/common/card/stories/NsFfgCard.stories.tsx +1 -1
  39. package/src/common/card/stories/{data.js → data.ts} +1 -25
  40. package/src/common/carousal/NsScrollingCarousal.tsx +26 -2
  41. package/src/common/carousal/stories/NsScrollingCarousal.stories.tsx +1 -1
  42. package/src/common/carousal/types.d.ts +2 -0
  43. package/src/common/cart-icon/NsCartIcon.stories.tsx +1 -1
  44. package/src/common/checkbox/NsCheckbox.stories.tsx +1 -1
  45. package/src/common/checkbox/NsCheckbox.styled.tsx +2 -2
  46. package/src/common/column-control/NsFlexColumns.tsx +5 -10
  47. package/src/common/column-control/NsGridColumns.tsx +5 -10
  48. package/src/common/column-control/specs/NsColumnControl.spec.tsx +1 -1
  49. package/src/common/column-control/specs/NsFlexColumns.spec.tsx +1 -1
  50. package/src/common/column-control/specs/NsGridColumns.spec.tsx +1 -1
  51. package/src/common/column-control/stories/DivArray.stories.tsx +18 -0
  52. package/src/common/column-control/stories/DivArray.tsx +63 -0
  53. package/src/common/column-control/stories/NsColumnControl.stories.tsx +6 -3
  54. package/src/common/column-control/stories/NsFlexColumns.stories.tsx +13 -9
  55. package/src/common/column-control/stories/NsGridColumns.stories.tsx +12 -8
  56. package/src/common/column-control/stories/common.tsx +1 -1
  57. package/src/common/column-control/styled/StyledFlex.tsx +7 -3
  58. package/src/common/column-control/styled/StyledGrid.tsx +9 -2
  59. package/src/common/column-control/styled/common.ts +2 -2
  60. package/src/common/column-control/types.d.ts +15 -16
  61. package/src/common/common.types.d.ts +1 -0
  62. package/src/common/dropdown/stories/NsDropdown.stories.tsx +1 -1
  63. package/src/common/dropdown/stories/NsDropdownCountry.stories.tsx +1 -1
  64. package/src/common/email-simple/NsEmailSimple.spec.tsx +145 -0
  65. package/src/common/email-simple/NsEmailSimple.stories.tsx +61 -0
  66. package/src/common/email-simple/NsEmailSimple.tsx +71 -0
  67. package/src/common/email-simple/index.ts +2 -0
  68. package/src/common/email-simple/types.d.ts +14 -0
  69. package/src/common/flag/NsFlag.spec.tsx +4 -25
  70. package/src/common/flag/NsFlag.stories.tsx +1 -1
  71. package/src/common/flag/NsFlag.tsx +0 -2
  72. package/src/common/icon/NsIcon.stories.tsx +1 -1
  73. package/src/common/image/NsImage.stories.tsx +1 -1
  74. package/src/common/image/NsNextImage.stories.tsx +1 -1
  75. package/src/common/image/types.d.ts +1 -0
  76. package/src/common/index.ts +3 -0
  77. package/src/common/input/NsInputField.stories.tsx +13 -10
  78. package/src/common/input/NsInputField.tsx +12 -5
  79. package/src/common/input/getAdornmentProps.tsx +4 -0
  80. package/src/common/input/types.d.ts +18 -1
  81. package/src/common/label/NsLabel.stories.tsx +5 -0
  82. package/src/common/label/NsLabel.tsx +16 -19
  83. package/src/common/label/types.d.ts +2 -1
  84. package/src/common/link/NsLink.stories.tsx +1 -1
  85. package/src/common/nav-product-card/NsNavProductCard.stories.tsx +1 -1
  86. package/src/common/nav-tab/NsNavTab.spec.tsx +0 -5
  87. package/src/common/nav-tab/NsNavTab.stories.tsx +1 -1
  88. package/src/common/radiogroup/NsRadioGroup.spec.tsx +63 -0
  89. package/src/common/radiogroup/NsRadioGroup.stories.tsx +101 -0
  90. package/src/common/radiogroup/NsRadioGroup.styled.tsx +56 -0
  91. package/src/common/radiogroup/NsRadioGroup.tsx +46 -0
  92. package/src/common/radiogroup/index.ts +2 -0
  93. package/src/common/radiogroup/types.d.ts +19 -0
  94. package/src/common/select/NsSelect.spec.tsx +200 -0
  95. package/src/common/select/NsSelect.styled.tsx +89 -0
  96. package/src/common/select/NsSelect.tsx +117 -0
  97. package/src/common/select/NsSelectOption.tsx +30 -0
  98. package/src/common/select/index.ts +3 -0
  99. package/src/common/select/stories/NsSelect.stories.tsx +134 -0
  100. package/src/common/select/types.d.ts +34 -0
  101. package/src/common/table/NsExpandableRow.tsx +68 -0
  102. package/src/common/table/NsTable.spec.tsx +69 -41
  103. package/src/common/table/NsTable.stories.tsx +48 -10
  104. package/src/common/table/NsTable.styled.ts +95 -4
  105. package/src/common/table/NsTable.tsx +78 -89
  106. package/src/common/table/NsTableHeader.tsx +52 -38
  107. package/src/common/table/NsTablePagination.tsx +21 -13
  108. package/src/common/table/types.d.ts +21 -8
  109. package/src/common/text-strip/NsTextStrip.stories.tsx +5 -4
  110. package/src/common/text-strip/NsTextStrip.tsx +5 -2
  111. package/src/common/text-strip/types.d.ts +7 -4
  112. package/src/common/typography/NsTypography.stories.tsx +1 -1
  113. package/src/common/validations/regex.ts +3 -0
  114. package/src/common/videos/NsVideo.stories.tsx +1 -1
  115. package/src/common/column-control/stories/NDivs.story.tsx +0 -35
  116. /package/src/common/card/{tests → specs}/BrandLogo.spec.tsx +0 -0
  117. /package/src/common/card/{tests → specs}/NsBgCard.spec.tsx +0 -0
  118. /package/src/common/card/{tests → specs}/NsBrandProductCard.spec.tsx +0 -0
  119. /package/src/common/card/{tests → specs}/NsFfgCard.spec.tsx +0 -0
  120. /package/src/common/carousal/{tests → specs}/Chevron.spec.tsx +0 -0
  121. /package/src/common/carousal/{tests → specs}/NsCarousal.spec.tsx +0 -0
  122. /package/src/common/carousal/{tests → specs}/NsScrollingCarousal.spec.tsx +0 -0
  123. /package/src/common/carousal/{tests → specs}/RenderBrand.spec.tsx +0 -0
@@ -1,33 +1,30 @@
1
- import { InputLabel } from '@mui/material';
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(InputLabel)(({ theme }: any) => {
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
- fontSize: '14px',
11
- color: theme.palette?.primary?.main ?? '#252525',
10
+ fontSize: fontSize ? `${fontSize}px` : '14px',
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
  };
@@ -6,7 +6,7 @@
6
6
 
7
7
  import React from 'react';
8
8
  import type { StoryObj, Meta } from '@storybook/react';
9
- import { withCenterDecorator } from '../../stories/decorators/withCenterDecorator';
9
+ import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
10
10
 
11
11
  import { NsLink } from './';
12
12
  import { NsTypography } from '../typography';
@@ -1,5 +1,5 @@
1
1
  import type { StoryObj, Meta } from '@storybook/react';
2
- import { withCenterDecorator } from '../../stories/decorators/withCenterDecorator';
2
+ import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
3
3
  import { NsNavProductCard } from './';
4
4
 
5
5
  type ComponentType = typeof NsNavProductCard;
@@ -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
  });
@@ -1,5 +1,5 @@
1
1
  import type { StoryObj, Meta } from '@storybook/react';
2
- import { withCenterDecorator } from '../../stories/decorators/withCenterDecorator';
2
+ import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
3
3
  import { NsNavTab } from './';
4
4
 
5
5
  type ComponentType = typeof NsNavTab;
@@ -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
+ })
@@ -0,0 +1,101 @@
1
+
2
+ import type { StoryObj, Meta } from '@storybook/react';
3
+ import { within, userEvent } from '@storybook/testing-library';
4
+ import { expect } from '@storybook/jest';
5
+ import { NsRadioGroup } from './'
6
+
7
+ type ComponentType = typeof NsRadioGroup;
8
+ type Story = StoryObj<ComponentType>;
9
+ type MetaStory = Meta<ComponentType>;
10
+
11
+ export default {
12
+ component: NsRadioGroup,
13
+ title: 'Components/NsRadioGroup',
14
+ argTypes: {
15
+ disable: {
16
+ description:
17
+ 'Indicates whether the radio button is enabled/disabled',
18
+
19
+ },
20
+ items: {
21
+ description:
22
+ 'Value of the component to be emitted when selected.',
23
+ },
24
+ name: {
25
+ description:
26
+ 'Name of the component',
27
+
28
+ },
29
+ label: {
30
+ description:
31
+ 'Label of the radio group',
32
+
33
+ },
34
+ color: {
35
+ description:
36
+ 'Color of the radio button',
37
+
38
+ },
39
+ size: {
40
+ description:
41
+ 'Margin Left for Additional Slot text',
42
+
43
+ },
44
+ labelFontSize: {
45
+ description:
46
+ 'Used to change font-size of the label'
47
+ },
48
+ additionalSlot: {
49
+ description:
50
+ 'An additional slot allows for more text',
51
+
52
+ }
53
+ },
54
+ } as MetaStory;
55
+
56
+ export const RadioGroup: Story = {
57
+ args: {
58
+ disable: false,
59
+ items: [
60
+ {
61
+ id: 'individual',
62
+ label: `Vendeur à domicile indépendant mandataire (The VDI mandataire
63
+ enters into sales or service agreements
64
+ with customers in the name and on behalf of the company.
65
+ His remuneration will be based on commissions made
66
+ on the sales of products to customers.)`,
67
+ value: 'individual',
68
+ },
69
+ {
70
+ id: ' retailer',
71
+ label: `Vendeur à domicile indépendant acheteur-revendeur
72
+ (The VDI acheteur-revendeur sells the company's products in his own name and behalf.
73
+ His remuneration will be based on commissions and on the margins made on the sales of
74
+ products to customers.)`,
75
+ value: 'retailer',
76
+ },
77
+ ],
78
+ name: 'test',
79
+ label: 'I choose to signup as',
80
+ color: '#272525',
81
+ additionalSlot: 'An additional slot allows for more text',
82
+ size: 10,
83
+ labelFontSize: 16,
84
+ additionalProps: {
85
+ testid: 'radio-group',
86
+ },
87
+ },
88
+ play: async ({ canvasElement }) => {
89
+ const canvas = within(canvasElement);
90
+ await userEvent.hover(canvas.getByTestId('radio-group'));
91
+ await expect(
92
+ canvas.getByText(
93
+ 'Vendeur à domicile indépendant mandataire (The VDI mandataire enters into sales or service agreements with customers in the name and on behalf of the company. His remuneration will be based on commissions made on the sales of products to customers.)'
94
+ )
95
+ ).toBeInTheDocument();
96
+ },
97
+ };
98
+
99
+
100
+
101
+
@@ -0,0 +1,56 @@
1
+ import { Radio, FormControlLabel, FormLabel, RadioGroup } from '@mui/material';
2
+ import { ColorUtils } from '@nuskin/foundation-theme';
3
+ import { styled, nuskinTheme } from '@nuskin/foundation-theme';
4
+
5
+ const { getPaletteColor } = ColorUtils;
6
+ const { colors } = nuskinTheme;
7
+
8
+ export const StyledHelperText = styled('div')`
9
+ margin-top :10px;
10
+ padding-left: 0.5em;
11
+ text-align: left;
12
+ justify-self: flex-start;
13
+ )`;
14
+
15
+ export const StyledSpan = styled('span')`
16
+ font-size: '16px';
17
+ font-weight: 300;
18
+ color: ${({ theme }) => getPaletteColor(theme, 'primary')};
19
+ `;
20
+
21
+ export const StyledLabel = styled(FormLabel)(({ theme }) => {
22
+ return {
23
+ color: getPaletteColor(theme, 'primary'),
24
+ marginBottom: '15px',
25
+ backgroundColor: 'transparent',
26
+ };
27
+ });
28
+
29
+ export const StyledRadio = styled(Radio)(({ theme }) => {
30
+ const isLight = theme.palette?.primary?.main === '#252525';
31
+
32
+ return {
33
+ color: isLight ? colors.primary.black : colors.primary.white,
34
+ };
35
+ });
36
+
37
+ export const StyledFormControlLabel = styled(FormControlLabel)(({ theme }) => {
38
+ const isLight = theme.palette?.primary?.main === '#252525';
39
+
40
+ return {
41
+ color: getPaletteColor(theme, 'primary'),
42
+ marginBottom: '10px',
43
+ '.MuiFormControlLabel-label.Mui-disabled': {
44
+ color: isLight ? colors?.neutral?.[60] : colors?.neutral?.[20],
45
+ },
46
+ };
47
+ });
48
+
49
+ export const StyledRadioGroup = styled(RadioGroup)(({ color }) => {
50
+ return {
51
+ marginTop: '10px',
52
+ '.MuiRadio-root.custom-radio.Mui-checked': {
53
+ color: color,
54
+ },
55
+ };
56
+ });
@@ -0,0 +1,46 @@
1
+ import { FormControl } from '@mui/material';
2
+ import { NsRadioGroupProps } from './types';
3
+ import {
4
+ StyledHelperText,
5
+ StyledFormControlLabel,
6
+ StyledRadio,
7
+ StyledSpan,
8
+ StyledRadioGroup,
9
+ } from './NsRadioGroup.styled';
10
+ import { NsLabel } from '../label';
11
+
12
+ const NsRadioGroup = (props: NsRadioGroupProps) => {
13
+ const { items, additionalSlot, label, onChange, color, disable, size, additionalProps, labelFontSize } = props;
14
+
15
+ return (
16
+ <>
17
+ <FormControl data-testid={additionalProps?.testid}>
18
+ <NsLabel size={labelFontSize}>{label}</NsLabel>
19
+ <StyledRadioGroup
20
+ aria-labelledby="demo-radio-buttons-group-label"
21
+ defaultValue={items?.[0]?.value}
22
+ name="radio-buttons-group"
23
+ onChange={onChange}
24
+ color={color}
25
+ >
26
+ {items?.map((item, index) => (
27
+ <StyledFormControlLabel
28
+ id={`${index} `}
29
+ key={item?.id}
30
+ value={item?.value}
31
+ control={<StyledRadio className="custom-radio" />}
32
+ label={item?.label}
33
+ disabled={disable}
34
+ />
35
+ ))}
36
+ </StyledRadioGroup>
37
+ </FormControl>
38
+ {additionalSlot && <StyledHelperText className={`ml-${size}`}>
39
+ <StyledSpan className="text-sm">{additionalSlot}</StyledSpan>
40
+ </StyledHelperText>}
41
+
42
+ </>
43
+ );
44
+ };
45
+
46
+ export default NsRadioGroup;
@@ -0,0 +1,2 @@
1
+ export { default as NsRadioGroup } from './NsRadioGroup';
2
+ export type { NsRadioGroupProps} from './types.d'
@@ -0,0 +1,19 @@
1
+ import { AdditionalProps } from '../common.types';
2
+
3
+ export type NsRadioGroupProps = AdditionalProps & {
4
+ disable : boolean ;
5
+ name : string;
6
+ additionalSlot : string;
7
+ label : string ;
8
+ items: RadioItems[] ;
9
+ color : string;
10
+ size : number;
11
+ labelFontSize:number,
12
+ onChange : () => void;
13
+ }
14
+
15
+ export type RadioItems = {
16
+ label : string ;
17
+ value :string | number ;
18
+ id: string | number;
19
+ }
@@ -0,0 +1,200 @@
1
+ import React from 'react';
2
+ import { render, fireEvent, screen, waitFor } from '@/test-utils/index';
3
+ import NsSelect from './NsSelect';
4
+ import NsSelectOption from './NsSelectOption';
5
+
6
+ function createSelectOptions(options: { value: string; label: string }[]) {
7
+ return options.map((option) => <NsSelectOption key={option.value} value={option.value} label={option.label} />);
8
+ }
9
+
10
+ describe('NsSelectOption', () => {
11
+ test('renders NsSelectOption component without errors', () => {
12
+ const value = 'option1';
13
+ const label = 'Option 1';
14
+ const { getByTestId, getByText } = render(
15
+ <NsSelectOption value={value} label={label} />
16
+ );
17
+
18
+ // Check if the option container element exists
19
+ const optionContainer = getByTestId(`option-${value}`);
20
+ expect(optionContainer).toBeInTheDocument();
21
+
22
+ // Check if the option label is rendered correctly
23
+ const optionLabel = getByText(label);
24
+ expect(optionLabel).toBeInTheDocument();
25
+ });
26
+ test('clicking on NsSelectOption selects the option', () => {
27
+ const value = 'option1';
28
+ const label = 'Option 1';
29
+ const onSelect = jest.fn();
30
+ const { getByTestId } = render(
31
+ <NsSelectOption value={value} label={label} onSelect={onSelect} />
32
+ );
33
+ const optionElement = getByTestId(`option-${value}`);
34
+ fireEvent.click(optionElement);
35
+ expect(onSelect).toHaveBeenCalledWith(value);
36
+ });
37
+
38
+ });
39
+
40
+ describe('NsSelect', () => {
41
+ const onSelect = jest.fn();
42
+ const selectedValue = '';
43
+ const selectedLabel = '';
44
+
45
+ const options = [
46
+ { value: 'Option1', label: 'Option 1' },
47
+ { value: 'Option2', label: 'Option 2' },
48
+ { value: 'Option3', label: 'Option 3' },
49
+ ];
50
+
51
+ it('renders the placeholder text when no value is selected', () => {
52
+ render(
53
+ <NsSelect
54
+ placeholder="Select an option"
55
+ selectedValue={selectedValue}
56
+ selectedLabel={selectedLabel}
57
+ onSelect={onSelect}
58
+ >
59
+ {createSelectOptions(options)}
60
+ </NsSelect>
61
+ );
62
+
63
+ expect(screen.getByText('Select an option')).toBeInTheDocument();
64
+ });
65
+
66
+ test('clicking outside the select container closes the dropdown', () => {
67
+ // const value = 'option1';
68
+ // const label = 'Option 1';
69
+ const onSelect = jest.fn();
70
+ const selectedLabel = 'Option 1';
71
+ const { getByTestId, queryByTestId } = render(
72
+ <NsSelect selectedValue="Option1" selectedLabel={selectedLabel} onSelect={onSelect}>
73
+ </NsSelect>
74
+ );
75
+ const selectButton = getByTestId('select-head');
76
+ fireEvent.mouseDown(selectButton);
77
+ const outsideElement = document.createElement('div');
78
+ fireEvent.mouseDown(outsideElement);
79
+ // Add assertions to check if the dropdown is closed (isOpen state is false)
80
+ expect(queryByTestId('option-Option1')).toBeNull();
81
+ });
82
+
83
+ it('renders the selected value label', () => {
84
+ const selectedLabel = 'Option 1';
85
+ render(
86
+ <NsSelect selectedValue="Option1" selectedLabel={selectedLabel} onSelect={onSelect}>
87
+ {createSelectOptions(options)}
88
+ </NsSelect>
89
+ );
90
+
91
+ expect(screen.getByText(selectedLabel)).toBeInTheDocument();
92
+ });
93
+
94
+ test('clicking on select button opens the dropdown', () => {
95
+ const { getByTestId, getByText } = render(
96
+ <NsSelect selectedValue="Option1" selectedLabel={selectedLabel} onSelect={onSelect}>
97
+ {createSelectOptions(options)}
98
+ </NsSelect>
99
+ );
100
+ const selectButton = getByTestId('select-head');
101
+ fireEvent.mouseDown(selectButton);
102
+
103
+ // Check if the dropdown is opened (isOpen state is true)
104
+ const dropdownList = getByTestId('select-list');
105
+ expect(dropdownList).toBeInTheDocument();
106
+
107
+ // Check if the options are rendered in the dropdown
108
+ const option1 = getByText('Option 1');
109
+ const option2 = getByText('Option 2');
110
+ expect(option1).toBeInTheDocument();
111
+ expect(option2).toBeInTheDocument();
112
+ });
113
+
114
+ test('disabling the select component prevents interaction', () => {
115
+ const onSelect = jest.fn();
116
+ const { getByTestId, queryByTestId } = render(
117
+ <NsSelect selectedValue="Option1" selectedLabel={selectedLabel} onSelect={onSelect} disabled>
118
+ <NsSelectOption value="option1" label="Option 1" onSelect={onSelect} />
119
+ <NsSelectOption value="option2" label="Option 2" onSelect={onSelect} />
120
+ </NsSelect>
121
+ );
122
+ const selectButton = getByTestId('select-head');
123
+ fireEvent.mouseDown(selectButton);
124
+
125
+ // Check if the dropdown does not open (select list is not present)
126
+ const dropdownList = queryByTestId('select-list');
127
+ expect(dropdownList).toBeNull();
128
+
129
+ // Check if the onSelect callback is not called
130
+ expect(onSelect).not.toHaveBeenCalled();
131
+ });
132
+
133
+ it('select closes on mouse leave when closeOnMouseLeave is set to true', async () => {
134
+ render(
135
+ <NsSelect
136
+ closeOnMouseLeave
137
+ selectedValue={selectedValue}
138
+ selectedLabel={selectedLabel}
139
+ onSelect={onSelect}
140
+ >
141
+ {createSelectOptions(options)}
142
+ </NsSelect>
143
+ );
144
+
145
+ const selectHead = screen.getByTestId('select-head');
146
+ fireEvent.click(selectHead);
147
+
148
+ // const selectList = screen.queryByTestId ('select-list');
149
+ const option1 = screen.queryByTestId('option-Option1');
150
+ const option2 = screen.queryByTestId('option-Option2');
151
+ const option3 = screen.queryByTestId('option-Option3');
152
+ fireEvent.click(selectHead);
153
+
154
+ await waitFor(() => {
155
+ expect(option1).not.toBeInTheDocument();
156
+ expect(option2).not.toBeInTheDocument();
157
+ expect(option3).not.toBeInTheDocument();
158
+ });
159
+ });
160
+ it('select does not open when disabled', () => {
161
+ render(
162
+ <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect} disabled>
163
+ {createSelectOptions(options)}
164
+ </NsSelect>
165
+ );
166
+
167
+ const selectHead = screen.getByTestId('select-head');
168
+ fireEvent.click(selectHead);
169
+
170
+ expect(screen.queryByTestId('select-list')).not.toBeInTheDocument();
171
+ });
172
+
173
+ it('opens the select on "ArrowDown" key press', () => {
174
+ render(
175
+ <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect}>
176
+ {createSelectOptions(options)}
177
+ </NsSelect>
178
+ );
179
+
180
+ const selectHead = screen.getByTestId('select-head');
181
+ fireEvent.keyDown(selectHead, { key: 'arrowDown' });
182
+
183
+ expect(selectHead).toBeInTheDocument();
184
+ });
185
+
186
+ test('renders SelectContainer with error styles when errorMessage is present', () => {
187
+ const errorMessage = 'Invalid value';
188
+ render(
189
+ <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect} errorMessage={errorMessage}>
190
+ {createSelectOptions(options)}
191
+ </NsSelect>
192
+ );
193
+
194
+ const selectContainer = screen.getByTestId('select-container');
195
+
196
+ expect(selectContainer).toHaveStyle('borderColor: red');
197
+ expect(selectContainer).toHaveStyle('color: red');
198
+ });
199
+
200
+ });