@nuskin/foundation-ui-components 1.0.0-develop.10 → 1.0.0-develop.11

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": "@nuskin/foundation-ui-components",
3
- "version": "1.0.0-develop.10",
3
+ "version": "1.0.0-develop.11",
4
4
  "description": "It is a foundation library written in react, that provides common components to all UI pages",
5
5
  "private": false,
6
6
  "main": "src/common/index.ts",
@@ -1,5 +1,12 @@
1
1
  import { styled } from '@nuskin/foundation-theme';
2
- import { AccordionVariant, AccordionVariantType, NsCollapseProps, AccordionItem, NsAccordion } from '../';
2
+ import {
3
+ AccordionVariant,
4
+ AccordionVariantType,
5
+ NsCollapseProps,
6
+ AccordionItem,
7
+ NsAccordion,
8
+ AccordionContentTypeObject,
9
+ } from '../';
3
10
  import { getAccordionColor } from './colorMap';
4
11
  import { ReactElement, isValidElement, useMemo } from 'react';
5
12
 
@@ -68,7 +75,7 @@ const NsCollapse = ({
68
75
  if (isValidElement(content)) {
69
76
  return content as ReactElement;
70
77
  }
71
- if (type === 'html') {
78
+ if (type === AccordionContentTypeObject.html) {
72
79
  return (
73
80
  <div
74
81
  className="nsa-content-padded"
@@ -76,13 +83,13 @@ const NsCollapse = ({
76
83
  {...(cslp?.content ?? {})}
77
84
  />
78
85
  );
79
- } else if (type === 'text') {
86
+ } else if (type === AccordionContentTypeObject.text) {
80
87
  return (
81
88
  <div className="p-4" {...(cslp?.content ?? {})}>
82
89
  {content as string}
83
90
  </div>
84
91
  );
85
- } else if (type === 'accordion') {
92
+ } else if (type === AccordionContentTypeObject.accordion) {
86
93
  return (
87
94
  <NsAccordion
88
95
  isChild={true}
@@ -6,3 +6,13 @@ export const AccordionVariant = {
6
6
  } as const;
7
7
  const variantValues = Object.values(AccordionVariant);
8
8
  export type AccordionVariantType = (typeof variantValues)[number];
9
+
10
+ export const AccordionContentTypeObject = {
11
+ text: 'text',
12
+ html: 'html',
13
+ accordion: 'accordion',
14
+ jsx: 'jsx',
15
+ };
16
+
17
+ const contentValues = Object.values(AccordionContentTypeObject);
18
+ export type AccordionContentType = (typeof contentValues)[number];
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { render, fireEvent, screen } from '@/test-utils/index';
3
- import { AccordionItem, AccordionVariant, NsAccordion } from '@/common/index';
3
+ import { AccordionContentTypeObject, AccordionItem, AccordionVariant, NsAccordion } from '@/common/index';
4
4
 
5
5
  const generateContentArray = (count: number, isDefaultOpen = true) => {
6
6
  const arr = [] as AccordionItem[];
@@ -9,7 +9,7 @@ const generateContentArray = (count: number, isDefaultOpen = true) => {
9
9
  title: `Title ${i}`,
10
10
  content: <div className="p-2">Content {i}</div>,
11
11
  isDefaultOpen,
12
- type:'jsx',
12
+ type: AccordionContentTypeObject.jsx,
13
13
  id: `Test ${i}`,
14
14
  });
15
15
  }
@@ -1,6 +1,6 @@
1
1
  import type { StoryObj, Meta } from '@storybook/react';
2
2
  import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
3
- import { AccordionVariant, NsCollapse } from '../';
3
+ import { AccordionContentTypeObject, AccordionVariant, NsCollapse } from '../';
4
4
  import NsAccordionStory from './NsAccordion.stories';
5
5
 
6
6
  type ComponentType = typeof NsCollapse;
@@ -26,7 +26,7 @@ export default {
26
26
  },
27
27
  type: {
28
28
  control: 'select',
29
- values: ['jsx', 'html', 'text', 'accordion'],
29
+ values: Object.values(AccordionContentTypeObject),
30
30
  description: 'This type should exactly match the content type to have accordion work correctly',
31
31
  },
32
32
  level: NsAccordionStory.argTypes.level,
@@ -1,4 +1,4 @@
1
- import { NsIconProps } from '../..';
1
+ import { AccordionContentTypeObject, NsIconProps } from '../..';
2
2
  import { AccordionItem } from '../types';
3
3
 
4
4
  const getItem = () => {
@@ -14,7 +14,7 @@ const getIcon = (name = '', color = '') => {
14
14
  };
15
15
  export const getTextContent = (text = '') => {
16
16
  return {
17
- type: 'text' as AccordionItem['type'],
17
+ type: AccordionContentTypeObject.text as AccordionItem['type'],
18
18
  content: text || dummyText,
19
19
  };
20
20
  };
@@ -33,7 +33,7 @@ function createAccordionItem1(): AccordionItem {
33
33
  icon: getIcon(),
34
34
  title: 'Example - 1 JSX',
35
35
  content: getJsxContent(),
36
- type: 'jsx',
36
+ type: AccordionContentTypeObject.jsx,
37
37
  isDefaultOpen: true,
38
38
  };
39
39
  }
@@ -43,14 +43,14 @@ function createAccordionItem2(): AccordionItem {
43
43
  isDefaultOpen: true,
44
44
  icon: getIcon(),
45
45
  title: 'Example - 2',
46
- type: 'accordion',
46
+ type: AccordionContentTypeObject.accordion,
47
47
  content: [
48
48
  { ...getItem(), title: 'Example - 2.1', ...getTextContent() },
49
49
  {
50
50
  ...getItem(),
51
51
  icon: getIcon('hamburgerIcon', 'success'),
52
52
  title: 'Example - 2.2',
53
- type: 'jsx',
53
+ type: AccordionContentTypeObject.jsx,
54
54
  content: <div className="p-2">Example 2.2 Content</div>,
55
55
  },
56
56
  ],
@@ -61,14 +61,14 @@ function createAccordionItem3(): AccordionItem {
61
61
  ...getItem(),
62
62
  icon: getIcon('hamburgerIcon', 'success'),
63
63
  title: 'Example - 3',
64
- type: 'accordion',
64
+ type: AccordionContentTypeObject.accordion,
65
65
  content: [
66
66
  createAccordionItem3_1(),
67
67
  {
68
68
  ...getItem(),
69
69
 
70
70
  title: 'Example - 3.2',
71
- type: 'text',
71
+ type: AccordionContentTypeObject.text,
72
72
  content: dummyText,
73
73
  },
74
74
  ],
@@ -80,18 +80,18 @@ export function createAccordionItem3_1(): AccordionItem {
80
80
  ...getItem(),
81
81
  title: 'Example - 3.1',
82
82
  allowMultipleExpanded: true,
83
- type: 'accordion',
83
+ type: AccordionContentTypeObject.accordion,
84
84
  content: [
85
85
  {
86
86
  ...getItem(),
87
87
  title: 'Example - 3.1.1',
88
- type: 'text',
88
+ type: AccordionContentTypeObject.text,
89
89
  content: dummyText,
90
90
  },
91
91
  {
92
92
  ...getItem(),
93
93
  title: 'Example - 3.1.2',
94
- type: 'text',
94
+ type: AccordionContentTypeObject.text,
95
95
  content: dummyText,
96
96
  },
97
97
  ],
@@ -103,13 +103,13 @@ function createAccordionItem4(): AccordionItem {
103
103
  ...getItem(),
104
104
  icon: getIcon(),
105
105
  title: 'Example - 4',
106
- type: 'accordion',
106
+ type: AccordionContentTypeObject.accordion,
107
107
  content: [
108
108
  createAccordionItem4_1(),
109
109
  {
110
110
  ...getItem(),
111
111
  title: 'Example - 4.2',
112
- type: 'html',
112
+ type: AccordionContentTypeObject.html,
113
113
  content: '<h2>Lorem ipsum dolor sit amet.</h2>',
114
114
  },
115
115
  ],
@@ -120,18 +120,18 @@ function createAccordionItem4_1(): AccordionItem {
120
120
  return {
121
121
  ...getItem(),
122
122
  title: 'Example - 4.1',
123
- type: 'accordion',
123
+ type: AccordionContentTypeObject.accordion,
124
124
  content: [
125
125
  {
126
126
  ...getItem(),
127
127
 
128
128
  title: 'Example - 4.1.1',
129
- type: 'text',
129
+ type: AccordionContentTypeObject.text,
130
130
  content: dummyText,
131
131
  },
132
132
  {
133
133
  ...getItem(),
134
- type: 'jsx',
134
+ type: AccordionContentTypeObject.jsx,
135
135
  content: <div className="p-3">Example 4.1.2. content</div>,
136
136
  title: 'Example - 4.1.2',
137
137
  },
@@ -2,11 +2,11 @@ import { ReactElement, ReactNode } from 'react';
2
2
  import { AdditionalProps } from '../common.types';
3
3
  import { NsIconNameType, NsIconProps } from '../icon';
4
4
  import { Variants } from '../typography';
5
- import { AccordionVariantType } from './enums';
5
+ import { AccordionContentType, AccordionVariantType } from './enums';
6
6
 
7
7
  export type AccordionItem = {
8
8
  allowMultipleExpanded?: boolean;
9
- type: 'text' | 'html' | 'accordion' | 'jsx';
9
+ type: AccordionContentType;
10
10
  id: string;
11
11
  content: string | AccordionItem[] | ReactElement;
12
12
  icon?: NsIconProps;
@@ -53,7 +53,7 @@ export type NsCollapseProps = AdditionalProps & {
53
53
  isOpen: boolean;
54
54
  isChild: boolean;
55
55
  allowMultipleExpanded?: boolean;
56
- type: 'text' | 'html' | 'accordion' | 'jsx';
56
+ type: AccordionContentType;
57
57
  } & CommonAccordionType;
58
58
 
59
59
  export type NsToggleSectionProps = AdditionalProps & {
@@ -61,7 +61,7 @@ export type NsToggleSectionProps = AdditionalProps & {
61
61
  /** if true, NsToggle is rendered in open state, that collapsible section is visible */
62
62
  defaultOpen?: boolean;
63
63
  isChild: boolean;
64
- type: 'text' | 'html' | 'accordion' | 'jsx';
64
+ type: AccordionContentType;
65
65
  } & Pick<CommonAccordionType, 'invert' | 'variant' | 'content'>;
66
66
 
67
67
  export type NsAccordionItemProps = AdditionalProps & {
@@ -76,6 +76,6 @@ export type NsAccordionItemProps = AdditionalProps & {
76
76
  closedIconName?: NsIconNameType;
77
77
  startIcon?: NsIconProps;
78
78
  isChild: boolean;
79
- type: 'text' | 'html' | 'accordion' | 'jsx';
79
+ type: AccordionContentType;
80
80
  allowMultipleExpanded?: boolean;
81
81
  } & CommonAccordionType;
@@ -5,25 +5,14 @@ const { getByTestId } = screen;
5
5
  describe('NsCartIcon', () => {
6
6
  it('renders Cart icon when item count is 0', () => {
7
7
  render(<NsCartIcon itemCount={0} color="primary" size="large" />);
8
- const cartIcon = getByTestId('cart-icon');
8
+ const cartIcon = getByTestId('cart-badge-icon');
9
9
  expect(cartIcon).toBeInTheDocument();
10
10
  });
11
- it('renders Cart icon with optional values', () => {
12
- render(<NsCartIcon itemCount={0} />);
13
- const cartIcon = getByTestId('cart-icon');
14
- expect(cartIcon).toBeInTheDocument();
15
- });
16
-
17
- it('renders Cart Badge icon when item count is greater than 0', () => {
18
- render(<NsCartIcon itemCount={5} color="primary" size="large" />);
19
- const cartBadgeIcon = getByTestId('cart-badge-icon');
20
- expect(cartBadgeIcon).toBeInTheDocument();
21
- });
22
11
 
23
12
  it('renders item count badge when item count is greater than 0', () => {
24
- render(<NsCartIcon itemCount={5} color="primary" size="large" />);
25
- const itemCountBadge = getByTestId('item-count-badge');
26
- expect(itemCountBadge).toBeInTheDocument();
27
- expect(itemCountBadge.textContent).toBe('5');
13
+ const itemCount = 5;
14
+ const { getByText } = render(<NsCartIcon itemCount={5} color="primary" size="large" />);
15
+ const badgeContentElement = getByText(itemCount.toString());
16
+ expect(badgeContentElement).toHaveTextContent('5'); // Adjust the value as per your badge content
28
17
  });
29
18
  });
@@ -19,7 +19,7 @@ export default {
19
19
  },
20
20
  },
21
21
  args: {
22
- itemCount: 1,
22
+ itemCount: 5,
23
23
  color: 'primary',
24
24
  size: 'large',
25
25
  },
@@ -1,40 +1,14 @@
1
- import { Theme } from '@mui/material';
1
+ import { Badge, Theme } from '@mui/material';
2
2
  import { styled, FoundationTheme } from '@nuskin/foundation-theme';
3
- import { NsIconSizeType } from '../icon/types';
4
3
 
5
4
  type ItemCountParams = {
6
- size: NsIconSizeType;
7
- color: FoundationTheme.PaletteColors;
8
5
  theme?: Theme;
6
+ bgcolor: FoundationTheme.PaletteColors;
9
7
  };
10
8
 
11
- export const CartIconContainer = styled.div`
12
- position: relative;
13
- display: inline-block;
14
- `;
15
-
16
- const BadgeFontSizeMap = {
17
- small: '8px',
18
- medium: '10px',
19
- large: '12px',
20
- xLarge: '14px',
21
- };
22
-
23
- const BadgePosMap = {
24
- small: '-8px',
25
- medium: '-6px',
26
- large: '-4px',
27
- xLarge: '-1px',
28
- };
29
-
30
- export const ItemCount = styled.span<ItemCountParams>`
31
- color: ${({ color, theme }) => theme?.palette?.[color]?.main};
32
- font-size: ${({ size }) => BadgeFontSizeMap[size]};
33
- right: ${({ size }) => BadgePosMap[size]};
34
- text-align: center;
35
- font-weight: 600;
36
- position: absolute;
37
- width: 32px;
38
- height: auto;
39
- top: -4px;
9
+ export const StyledBadge = styled(Badge) <ItemCountParams>`
10
+ & .MuiBadge-badge {
11
+ background-color: ${({ bgcolor, theme }) => theme?.palette?.[bgcolor]?.main};
12
+ color: ${({ bgcolor, theme }) => theme?.palette?.[bgcolor]?.contrastText};
13
+ }
40
14
  `;
@@ -1,21 +1,12 @@
1
1
  import { NsIcon } from '../icon';
2
- import { CartIconContainer, ItemCount } from './NsCartIcon.styled';
2
+ import { StyledBadge } from './NsCartIcon.styled';
3
3
  import { NsCartIconProps } from './types.d';
4
4
 
5
- const NsCartIcon = ({ itemCount, size = 'large', color = 'primary' }: NsCartIconProps) => {
5
+ const NsCartIcon = ({ itemCount = 0, size = 'large', color = 'primary', maxItemCount = 999 }: NsCartIconProps) => {
6
6
  return (
7
- <CartIconContainer>
8
- {itemCount > 0 ? (
9
- <NsIcon testId="cart-badge-icon" name="cartBadge" color={color} size={size} />
10
- ) : (
11
- <NsIcon testId="cart-icon" name="cart" color={color} size={size} />
12
- )}
13
- {itemCount > 0 && (
14
- <ItemCount data-testid="item-count-badge" color={color} size={size}>
15
- {itemCount}
16
- </ItemCount>
17
- )}
18
- </CartIconContainer>
7
+ <StyledBadge badgeContent={itemCount} max={maxItemCount} bgcolor={color}>
8
+ <NsIcon testId="cart-badge-icon" name="cart" size={size} color={color} />
9
+ </StyledBadge>
19
10
  );
20
11
  };
21
12
 
@@ -4,4 +4,5 @@ export type NsCartIconProps = {
4
4
  itemCount: number;
5
5
  size?: 'small' | 'medium' | 'large' | 'xLarge';
6
6
  color?: FoundationTheme.PaletteColors;
7
+ maxItemCount?:number;
7
8
  };
@@ -4,38 +4,13 @@ import { SvgIconProps, SvgIcon } from '@mui/material';
4
4
 
5
5
  const Cart = (props: SvgIconProps) => {
6
6
  return (
7
- <SvgIcon
8
- viewBox="0 0 20 20"
9
- preserveAspectRatio="xMidYMid meet"
10
- focusable="false"
11
- {...props}
12
- data-testid="cart"
13
- >
14
- <g
15
- id="cart-icon"
16
- fill="none"
17
- strokeWidth="1"
18
- stroke="currentColor"
19
- transform="translate(-53.000000, -15.000000)"
20
- >
21
- <g id="Group">
22
- <g id="cart-icon" transform="translate(49.000000, 8.000000)">
23
- <g id="Asset-9Cart" transform="translate(4.000000, 8.000000)">
24
- <circle id="Oval" cx="7" cy="14.5" r="1"></circle>
25
- <circle id="Oval" cx="15" cy="14.5" r="1"></circle>
26
- <polyline
27
- id="Shape"
28
- strokeLinecap="round"
29
- points="5.68434189e-14 0 3 0 6 12 16 12"
30
- ></polyline>
31
- <path
32
- d="M5.5,9 C16.0765368,9 17.2536948,8.11206806 17.6216676,6.82416338 L19,2 L3.5,2"
33
- id="Shape"
34
- ></path>
35
- </g>
36
- </g>
37
- </g>
38
- </g>
7
+ <SvgIcon viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-testid="cart" {...props}>
8
+ <path
9
+ fillRule="evenodd"
10
+ clipRule="evenodd"
11
+ d="M0 3.79999C0 3.2477 0.447715 2.79999 1 2.79999H3.19159C4.13466 2.79999 4.94959 3.45879 5.14719 4.38093L5.237 4.80005H21C21.3079 4.80005 21.5987 4.94192 21.7882 5.18464C21.9777 5.42735 22.0448 5.74384 21.9701 6.04258L20.5382 11.7702C20.0931 13.5509 18.4931 14.8 16.6577 14.8H7.3798L7.59407 15.8H19C19.5523 15.8 20 16.2478 20 16.8C20 17.3523 19.5523 17.8 19 17.8H18H7.5H6.78564C6.3141 17.8 5.90664 17.4706 5.80784 17.0096L3.45079 6.00958L3.19159 4.79999H1C0.447715 4.79999 0 4.35227 0 3.79999ZM7.5 17.8C6.39543 17.8 5.5 18.6955 5.5 19.8C5.5 20.9046 6.39543 21.8 7.5 21.8C8.60457 21.8 9.5 20.9046 9.5 19.8C9.5 18.6955 8.60457 17.8 7.5 17.8ZM18 17.8C16.8954 17.8 16 18.6955 16 19.8C16 20.9046 16.8954 21.8 18 21.8C19.1046 21.8 20 20.9046 20 19.8C20 18.6955 19.1046 17.8 18 17.8ZM6.95124 12.8H16.6577C17.5754 12.8 18.3754 12.1755 18.598 11.2851L19.7192 6.80005H5.66557L6.95124 12.8Z"
12
+ fill={props.color}
13
+ />
39
14
  </SvgIcon>
40
15
  );
41
16
  };