@nuskin/foundation-ui-components 1.0.0-develop.1 → 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 +21 -11
- package/src/common/accordion/NsAccordion.tsx +69 -0
- package/src/common/accordion/NsAccordionHeader.tsx +77 -0
- package/src/common/accordion/NsAccordionItem.tsx +59 -0
- package/src/common/accordion/NsCollapse.tsx +117 -0
- package/src/common/accordion/NsToggleSection.tsx +43 -0
- package/src/common/accordion/ToggleSection.styled.tsx +32 -0
- package/src/common/accordion/colorMap.ts +117 -0
- package/src/common/accordion/enums.ts +18 -0
- package/src/common/accordion/index.ts +7 -0
- package/src/common/accordion/specs/NsAccordion.spec.tsx +163 -0
- package/src/common/accordion/specs/NsAccordionHeader.spec.tsx +130 -0
- package/src/common/accordion/specs/NsAccordionItem.spec.tsx +79 -0
- package/src/common/accordion/specs/NsCollapse.spec.tsx +129 -0
- package/src/common/accordion/specs/NsToggleSection.spec.tsx +74 -0
- package/src/common/accordion/stories/NsAccordion.stories.tsx +65 -0
- package/src/common/accordion/stories/NsAccordionHeader.stories.tsx +44 -0
- package/src/common/accordion/stories/NsAccordionItem.stories.tsx +45 -0
- package/src/common/accordion/stories/NsCollapse.stories.tsx +50 -0
- package/src/common/accordion/stories/NsToggleSection.stories.tsx +26 -0
- package/src/common/accordion/stories/data.tsx +143 -0
- package/src/common/accordion/types.d.ts +81 -0
- package/src/common/alert/Header.tsx +29 -0
- package/src/common/alert/NsAlert.spec.tsx +62 -29
- package/src/common/alert/NsAlert.stories.tsx +18 -17
- package/src/common/alert/NsAlert.styled.tsx +124 -0
- package/src/common/alert/NsAlert.tsx +27 -110
- package/src/common/alert/index.ts +2 -2
- package/src/common/alert/types.d.ts +23 -23
- package/src/common/auth-dropdown/NsAuthDropdown.spec.tsx +24 -6
- package/src/common/auth-dropdown/NsAuthDropdown.stories.tsx +2 -2
- package/src/common/auth-dropdown/NsAuthDropdown.styled.ts +21 -16
- package/src/common/auth-dropdown/NsAuthDropdown.tsx +7 -6
- package/src/common/auth-dropdown/index.ts +1 -1
- package/src/common/auth-dropdown/types.d.ts +3 -1
- package/src/common/autocomplete/NsAutocomplete.spec.tsx +69 -24
- package/src/common/autocomplete/NsAutocomplete.stories.tsx +64 -7
- package/src/common/autocomplete/NsAutocomplete.styled.tsx +12 -0
- package/src/common/autocomplete/NsAutocomplete.tsx +100 -46
- package/src/common/autocomplete/index.ts +2 -1
- package/src/common/autocomplete/mock/MockData.ts +50 -7
- package/src/common/autocomplete/mock/MockUI.tsx +2 -1
- package/src/common/autocomplete/{types.ts → types.d.ts} +18 -8
- package/src/common/banner/NsBanner.spec.tsx +13 -4
- package/src/common/banner/NsBanner.stories.tsx +2 -2
- package/src/common/banner/NsBanner.styled.tsx +1 -1
- package/src/common/banner/NsBanner.tsx +1 -1
- package/src/common/banner/index.ts +1 -1
- package/src/common/brand-components/NsBrand.stories.tsx +2 -2
- package/src/common/brand-components/NsBrandComponent.tsx +6 -3
- package/src/common/brand-components/index.ts +1 -1
- package/src/common/breadcrumb/NsBreadcrumb.spec.tsx +8 -9
- package/src/common/breadcrumb/NsBreadcrumb.stories.tsx +3 -5
- package/src/common/breadcrumb/NsBreadcrumb.tsx +5 -3
- package/src/common/breadcrumb/data.ts +10 -0
- package/src/common/breadcrumb/index.ts +1 -1
- package/src/common/button/NsButton.spec.tsx +66 -51
- package/src/common/button/NsButton.stories.tsx +61 -4
- package/src/common/button/NsButton.styled.tsx +54 -72
- package/src/common/button/NsButton.tsx +9 -3
- package/src/common/button/helper.ts +82 -0
- package/src/common/button/index.ts +1 -1
- package/src/common/button/types.d.ts +3 -0
- package/src/common/card/NsFfgCard.tsx +14 -8
- package/src/common/card/specs/NsFfgCard.spec.tsx +33 -0
- package/src/common/card/stories/NsBgCard.stories.tsx +2 -4
- package/src/common/card/stories/NsBrandProductCard.stories.tsx +2 -2
- package/src/common/card/stories/NsFfgCard.stories.tsx +49 -16
- package/src/common/card/stories/{data.js → data.ts} +1 -25
- package/src/common/card/styled/NsFfgStyled.tsx +9 -7
- package/src/common/card/types.d.ts +7 -4
- package/src/common/carousal/NsScrollingCarousal.tsx +61 -0
- package/src/common/carousal/index.ts +3 -0
- package/src/common/carousal/{tests → specs}/NsCarousal.spec.tsx +2 -2
- package/src/common/carousal/specs/NsScrollingCarousal.spec.tsx +61 -0
- package/src/common/carousal/stories/NSCarousal.stories.tsx +2 -2
- package/src/common/carousal/stories/NsScrollingCarousal.stories.tsx +52 -0
- package/src/common/carousal/types.d.ts +23 -0
- package/src/common/cart-icon/NsCartIcon.spec.tsx +6 -17
- package/src/common/cart-icon/NsCartIcon.stories.tsx +3 -3
- package/src/common/cart-icon/NsCartIcon.styled.ts +7 -33
- package/src/common/cart-icon/NsCartIcon.tsx +6 -15
- package/src/common/cart-icon/index.ts +1 -1
- package/src/common/cart-icon/types.d.ts +1 -0
- package/src/common/checkbox/NsCheckbox.spec.tsx +2 -2
- package/src/common/checkbox/NsCheckbox.stories.tsx +2 -2
- package/src/common/checkbox/NsCheckbox.styled.tsx +15 -16
- package/src/common/checkbox/NsCheckbox.tsx +2 -2
- package/src/common/checkbox/index.ts +1 -1
- package/src/common/checkbox/types.d.ts +1 -7
- package/src/common/column-control/NsColumnControl.tsx +1 -1
- package/src/common/column-control/NsFlexColumns.tsx +22 -0
- package/src/common/column-control/NsGridColumns.tsx +22 -0
- package/src/common/column-control/index.ts +3 -1
- package/src/common/column-control/{NsColumnControl.spec.tsx → specs/NsColumnControl.spec.tsx} +3 -3
- package/src/common/column-control/specs/NsFlexColumns.spec.tsx +24 -0
- package/src/common/column-control/specs/NsGridColumns.spec.tsx +24 -0
- package/src/common/column-control/stories/DivArray.stories.tsx +18 -0
- package/src/common/column-control/stories/DivArray.tsx +63 -0
- package/src/common/column-control/{NsColumnControl.stories.tsx → stories/NsColumnControl.stories.tsx} +9 -16
- package/src/common/column-control/stories/NsFlexColumns.stories.tsx +63 -0
- package/src/common/column-control/stories/NsGridColumns.stories.tsx +63 -0
- package/src/common/column-control/stories/common.tsx +14 -0
- package/src/common/column-control/styled/StyledFlex.tsx +45 -0
- package/src/common/column-control/styled/StyledGrid.tsx +40 -0
- package/src/common/column-control/styled/common.ts +27 -0
- package/src/common/column-control/types.d.ts +15 -16
- package/src/common/column-control/utils.ts +5 -5
- package/src/common/common.types.d.ts +21 -0
- package/src/common/dropdown/NsDropdown.spec.tsx +1 -1
- package/src/common/dropdown/NsDropdown.styled.tsx +23 -18
- package/src/common/dropdown/NsDropdown.tsx +1 -1
- package/src/common/dropdown/NsDropdownOption.tsx +1 -1
- package/src/common/dropdown/index.ts +1 -1
- package/src/common/dropdown/stories/NsDropdown.stories.tsx +2 -2
- package/src/common/dropdown/stories/NsDropdownCountry.stories.tsx +2 -2
- package/src/common/dropdown/types.d.ts +3 -1
- package/src/common/email-simple/NsEmailSimple.spec.tsx +145 -0
- package/src/common/email-simple/NsEmailSimple.stories.tsx +61 -0
- package/src/common/email-simple/NsEmailSimple.tsx +71 -0
- package/src/common/email-simple/index.ts +2 -0
- package/src/common/email-simple/types.d.ts +14 -0
- package/src/common/flag/NsFlag.spec.tsx +5 -25
- package/src/common/flag/NsFlag.stories.tsx +2 -2
- package/src/common/flag/NsFlag.styled.tsx +7 -9
- package/src/common/flag/NsFlag.tsx +1 -3
- package/src/common/flag/index.ts +1 -1
- package/src/common/flag/types.d.ts +0 -2
- package/src/common/hooks/index.ts +2 -0
- package/src/common/hooks/specs/useWindowSize.spec.tsx +19 -0
- package/src/common/hooks/useAccordionMap.tsx +39 -0
- package/src/common/hooks/useWindowSize.tsx +30 -0
- package/src/common/icon/NsIcon.spec.tsx +1 -1
- package/src/common/icon/NsIcon.stories.tsx +2 -2
- package/src/common/icon/NsIcon.styled.tsx +1 -1
- package/src/common/icon/NsIcon.tsx +1 -1
- package/src/common/icon/NsIconVariants.ts +9 -4
- package/src/common/icon/icons/AlertErrorIcon.tsx +15 -6
- package/src/common/icon/icons/Cart.tsx +7 -32
- package/src/common/icon/icons/HamburgerIcon.tsx +29 -0
- package/src/common/icon/icons/UserIcon.tsx +30 -0
- package/src/common/icon/icons/WarningIcon.tsx +14 -5
- package/src/common/icon/index.ts +1 -1
- package/src/common/icon/types.d.ts +1 -0
- package/src/common/image/NsImage.spec.tsx +57 -7
- package/src/common/image/NsImage.stories.tsx +2 -2
- package/src/common/image/NsImage.tsx +24 -12
- package/src/common/image/NsNextImage.spec.tsx +1 -1
- package/src/common/image/NsNextImage.stories.tsx +2 -2
- package/src/common/image/NsNextImage.tsx +1 -1
- package/src/common/image/index.ts +1 -1
- package/src/common/image/types.d.ts +1 -0
- package/src/common/index.ts +14 -10
- package/src/common/input/InputFieldWrapper.tsx +4 -4
- package/src/common/input/InputWrapper.tsx +12 -7
- package/src/common/input/NsInputField.stories.tsx +13 -10
- package/src/common/input/NsInputField.tsx +13 -6
- package/src/common/input/getAdornmentProps.tsx +5 -1
- package/src/common/input/index.ts +1 -1
- package/src/common/input/types.d.ts +18 -1
- package/src/common/label/NsLabel.stories.tsx +6 -1
- package/src/common/label/NsLabel.tsx +21 -20
- package/src/common/label/index.ts +1 -1
- package/src/common/label/types.d.ts +2 -1
- package/src/common/link/NsLink.spec.tsx +1 -1
- package/src/common/link/NsLink.stories.tsx +2 -2
- package/src/common/link/NsLink.tsx +1 -1
- package/src/common/link/index.ts +1 -1
- package/src/common/modal/NsModal.spec.tsx +46 -0
- package/src/common/modal/NsModal.styled.tsx +28 -0
- package/src/common/modal/NsModal.tsx +37 -0
- package/src/common/modal/helper-component/NsModalContentBox.tsx +32 -0
- package/src/common/modal/helper-component/NsModalDefault.tsx +25 -0
- package/src/common/modal/helper-component/NsModalStatus.tsx +15 -0
- package/src/common/modal/helper-component/NsModalStatusIcon.tsx +14 -0
- package/src/common/modal/helper-component/NsModalTitle.tsx +26 -0
- package/src/common/modal/index.ts +2 -0
- package/src/common/modal/model/NsModalVariantMap.tsx +24 -0
- package/src/common/modal/stories/NsModal.stories.tsx +86 -0
- package/src/common/modal/stories/mock.tsx +46 -0
- package/src/common/modal/types.ts +56 -0
- package/src/common/nav-product-card/NsNavProductCard.spec.tsx +1 -1
- package/src/common/nav-product-card/NsNavProductCard.stories.tsx +2 -2
- package/src/common/nav-product-card/NsNavProductCard.tsx +1 -1
- package/src/common/nav-product-card/index.ts +1 -1
- package/src/common/nav-tab/NsNavTab.spec.tsx +2 -7
- package/src/common/nav-tab/NsNavTab.stories.tsx +2 -2
- package/src/common/nav-tab/NsNavTab.styled.tsx +7 -4
- package/src/common/nav-tab/NsNavTab.tsx +1 -1
- package/src/common/nav-tab/index.ts +1 -1
- package/src/common/nav-tab/types.d.ts +2 -2
- package/src/common/radiogroup/NsRadioGroup.spec.tsx +63 -0
- package/src/common/radiogroup/NsRadioGroup.stories.tsx +84 -0
- package/src/common/radiogroup/NsRadioGroup.styled.tsx +52 -0
- package/src/common/radiogroup/NsRadioGroup.tsx +62 -0
- package/src/common/radiogroup/index.ts +2 -0
- package/src/common/radiogroup/types.d.ts +20 -0
- package/src/common/search-bar/NsSeachBar.spec.tsx +1 -1
- package/src/common/search-bar/NsSearchBar.tsx +1 -3
- package/src/common/select/NsSelect.spec.tsx +193 -0
- package/src/common/select/NsSelect.styled.tsx +104 -0
- package/src/common/select/NsSelect.tsx +117 -0
- package/src/common/select/NsSelectOption.tsx +30 -0
- package/src/common/select/index.ts +3 -0
- package/src/common/select/stories/NsSelect.stories.tsx +134 -0
- package/src/common/select/types.d.ts +34 -0
- package/src/common/spinner/NsSpinner.spec.tsx +21 -0
- package/src/common/spinner/NsSpinner.stories.tsx +26 -0
- package/src/common/spinner/NsSpinner.styled.tsx +344 -0
- package/src/common/spinner/NsSpinner.tsx +14 -0
- package/src/common/spinner/icons/Spinner.tsx +161 -0
- package/src/common/spinner/index.ts +2 -0
- package/src/common/spinner/types.ts +5 -0
- package/src/common/table/NsExpandableRow.tsx +68 -0
- package/src/common/table/NsTable.spec.tsx +174 -0
- package/src/common/table/NsTable.stories.tsx +161 -0
- package/src/common/table/NsTable.styled.ts +127 -0
- package/src/common/table/NsTable.tsx +133 -0
- package/src/common/table/NsTableHeader.tsx +41 -0
- package/src/common/table/NsTablePagination.tsx +28 -0
- package/src/common/table/helper.ts +33 -0
- package/src/common/table/index.ts +2 -0
- package/src/common/table/types.d.ts +57 -0
- package/src/common/text-strip/NsTextStrip.spec.tsx +30 -0
- package/src/common/text-strip/NsTextStrip.stories.tsx +33 -0
- package/src/common/text-strip/NsTextStrip.tsx +47 -0
- package/src/common/text-strip/index.ts +2 -0
- package/src/common/text-strip/types.d.ts +17 -0
- package/src/common/typography/NsTypography.stories.tsx +2 -2
- package/src/common/typography/NsTypography.tsx +1 -1
- package/src/common/typography/Typography.styled.tsx +4 -4
- package/src/common/typography/index.ts +1 -1
- package/src/common/util.ts +1 -0
- package/src/common/utility/Show.tsx +13 -0
- package/src/common/utility/index.ts +1 -0
- package/src/common/validations/regex.ts +3 -0
- package/src/common/videos/NsVideo.stories.tsx +2 -2
- package/src/common/videos/NsVideo.tsx +1 -1
- package/src/common/videos/index.ts +1 -1
- package/src/common/videos/types.d.ts +1 -1
- package/src/common/alert/NsAlert.styled.ts +0 -124
- package/src/common/card/tests/NsFfgCard.spec.tsx +0 -23
- package/src/common/column-control/NDivs.story.tsx +0 -35
- package/src/common/common.types.ts +0 -10
- /package/src/common/brand-components/{NsBrandContanier.styled.tsx → NsBrandContainer.styled.tsx} +0 -0
- /package/src/common/card/{tests → specs}/BrandLogo.spec.tsx +0 -0
- /package/src/common/card/{tests → specs}/NsBgCard.spec.tsx +0 -0
- /package/src/common/card/{tests → specs}/NsBrandProductCard.spec.tsx +0 -0
- /package/src/common/carousal/{tests → specs}/Chevron.spec.tsx +0 -0
- /package/src/common/carousal/{tests → specs}/RenderBrand.spec.tsx +0 -0
|
@@ -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,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,15 @@
|
|
|
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
|
-
import { render } from '../../../test-utils/index';
|
|
12
|
-
import NsFlag from './NsFlag';
|
|
13
2
|
|
|
14
|
-
|
|
3
|
+
import { render } from '@/test-utils/index';
|
|
4
|
+
import { NsFlag } from '../';
|
|
15
5
|
|
|
16
|
-
// Test suite for FlagComponent
|
|
17
6
|
describe('FlagComponent', () => {
|
|
18
|
-
// Test case for rendering a div element with background color and text.
|
|
19
7
|
it('renders a div element with background color and text', () => {
|
|
20
|
-
|
|
8
|
+
const text = 'NU SKIN';
|
|
21
9
|
const { getByText } = render(<NsFlag message="NU SKIN" color="accentColorA" />);
|
|
10
|
+
const divElement = getByText(text);
|
|
22
11
|
|
|
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
12
|
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');
|
|
13
|
+
expect(divElement).toHaveTextContent(text);
|
|
34
14
|
});
|
|
35
15
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
-
import { withCenterDecorator } from '
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
3
|
import { NsFlag } from './';
|
|
4
4
|
|
|
5
5
|
type ComponentType = typeof NsFlag;
|
|
@@ -7,7 +7,7 @@ type Story = StoryObj<ComponentType>;
|
|
|
7
7
|
type MetaStory = Meta<ComponentType>;
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
title: 'Components/NsFlag',
|
|
10
|
+
title: 'Components/Data Display/NsFlag',
|
|
11
11
|
component: NsFlag,
|
|
12
12
|
decorators: [withCenterDecorator],
|
|
13
13
|
argTypes: {
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
import { Theme } from '@mui/material';
|
|
8
8
|
import { styled, ColorUtils, FoundationTheme } from '@nuskin/foundation-theme';
|
|
9
9
|
|
|
10
|
-
import { NsFlagSize } from './types';
|
|
10
|
+
import { NsFlagSize } from './types.d';
|
|
11
|
+
|
|
12
|
+
const { paletteColor } = ColorUtils;
|
|
11
13
|
|
|
12
14
|
type NsFlagThemeParams = {
|
|
13
15
|
$size: NsFlagSize;
|
|
@@ -33,13 +35,9 @@ const makeFlagSize = ({ $size }: { $size: NsFlagSize }) => {
|
|
|
33
35
|
return sizeValue / FLAG_SCALE_VALUE;
|
|
34
36
|
};
|
|
35
37
|
|
|
36
|
-
const {
|
|
37
|
-
getPaletteColor,
|
|
38
|
-
} = ColorUtils;
|
|
39
|
-
|
|
40
|
-
const makeFlagBorder = ({ $size, $bgColor = 'accentColorA', theme}: NsFlagThemeParams) => {
|
|
38
|
+
const makeFlagBorder = ({ $size, $bgColor = 'accentColorA', theme }: NsFlagThemeParams) => {
|
|
41
39
|
if (theme) {
|
|
42
|
-
return `${makeFlagSize({ $size })}px solid ${
|
|
40
|
+
return `${makeFlagSize({ $size })}px solid ${paletteColor($bgColor)({ theme })}`;
|
|
43
41
|
}
|
|
44
42
|
return '';
|
|
45
43
|
};
|
|
@@ -47,8 +45,8 @@ const makeFlagBorder = ({ $size, $bgColor = 'accentColorA', theme}: NsFlagThemeP
|
|
|
47
45
|
export const StyledFlag = styled('span')<NsFlagThemeParams>`
|
|
48
46
|
min-width: 29px;
|
|
49
47
|
height: ${getFlagHeight}px;
|
|
50
|
-
color: ${({ $bgColor = 'accentColorA', theme }) =>
|
|
51
|
-
background: ${({ $bgColor = 'accentColorA', theme }) =>
|
|
48
|
+
color: ${({ $bgColor = 'accentColorA', theme }) => paletteColor($bgColor, 'contrastText')({ theme })};
|
|
49
|
+
background: ${({ $bgColor = 'accentColorA', theme }) => paletteColor($bgColor)({ theme })};
|
|
52
50
|
position: relative;
|
|
53
51
|
padding: 0 15px;
|
|
54
52
|
display: inline-grid;
|
|
@@ -5,10 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import React, { PropsWithChildren } from 'react';
|
|
8
|
-
|
|
9
8
|
import { StyledFlag } from './NsFlag.styled';
|
|
10
|
-
|
|
11
|
-
import { NsFlagProps } from './types';
|
|
9
|
+
import { NsFlagProps } from './types.d';
|
|
12
10
|
|
|
13
11
|
const NsFlag = (props: PropsWithChildren<NsFlagProps>) => {
|
|
14
12
|
const { className = '', size = 'small', color = 'accentColorA', message, testId = 'ns-flag-component' } = props;
|
package/src/common/flag/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as NsFlag } from './NsFlag';
|
|
2
|
-
export type { NsFlagProps, NsFlagSize } from './types';
|
|
2
|
+
export type { NsFlagProps, NsFlagSize } from './types.d';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react-hooks';
|
|
2
|
+
import useWindowSize from '../useWindowSize';
|
|
3
|
+
|
|
4
|
+
describe('useWindowSize', () => {
|
|
5
|
+
it('should return the window size', () => {
|
|
6
|
+
const { result } = renderHook(useWindowSize);
|
|
7
|
+
expect(result.current).toEqual({ width: window.innerWidth, height: window.innerHeight });
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should update the window size when the window is resized', () => {
|
|
11
|
+
const { result } = renderHook(() => useWindowSize());
|
|
12
|
+
act(() => {
|
|
13
|
+
window.innerWidth = 500;
|
|
14
|
+
window.innerHeight = 500;
|
|
15
|
+
window.dispatchEvent(new Event('resize'));
|
|
16
|
+
});
|
|
17
|
+
expect(result.current).toEqual({ width: 500, height: 500 });
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
type ItemMap = Record<string, boolean>;
|
|
4
|
+
type UseAccordionProp = {
|
|
5
|
+
allowMultipleExpanded?: boolean;
|
|
6
|
+
defaultOpenIds?: string[];
|
|
7
|
+
};
|
|
8
|
+
const reducer = (map: ItemMap, id: string) => {
|
|
9
|
+
map[id] = true;
|
|
10
|
+
return map;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const useAccordionMap = ({ allowMultipleExpanded, defaultOpenIds }: UseAccordionProp) => {
|
|
14
|
+
const mapSetter = useCallback(() => {
|
|
15
|
+
let ids = defaultOpenIds;
|
|
16
|
+
if (!allowMultipleExpanded) {
|
|
17
|
+
ids = ids?.slice(0, 1) ?? [];
|
|
18
|
+
}
|
|
19
|
+
return ids?.reduce(reducer, {}) ?? {};
|
|
20
|
+
}, [defaultOpenIds, allowMultipleExpanded]);
|
|
21
|
+
|
|
22
|
+
const [itemStateMap, setItemMap] = useState<ItemMap>(mapSetter);
|
|
23
|
+
|
|
24
|
+
const toggleOpen = (index: string | number) => {
|
|
25
|
+
const key = index + '';
|
|
26
|
+
if (allowMultipleExpanded) {
|
|
27
|
+
setItemMap((prevState) => ({ ...prevState, [key]: !prevState[key] }));
|
|
28
|
+
} else {
|
|
29
|
+
setItemMap({ [key]: !itemStateMap[index] });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
setItemMap(mapSetter);
|
|
35
|
+
}, [mapSetter]);
|
|
36
|
+
return { itemStateMap, toggleOpen };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default useAccordionMap;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useWindowSize = () => {
|
|
4
|
+
const [windowSize, setWindowSize] = useState({
|
|
5
|
+
width: window.innerWidth,
|
|
6
|
+
height: window.innerHeight,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
function handleResize() {
|
|
11
|
+
setWindowSize({
|
|
12
|
+
width: window?.innerWidth || 300,
|
|
13
|
+
height: window?.innerHeight || 300,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (typeof window !== 'undefined') {
|
|
17
|
+
window.addEventListener('resize', handleResize);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return () => {
|
|
21
|
+
if (typeof window !== 'undefined') {
|
|
22
|
+
window.removeEventListener('resize', handleResize);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
return windowSize;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default useWindowSize;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
-
import { withCenterDecorator } from '
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
3
|
import { NsIcon, NsIconVariants } from './';
|
|
4
4
|
|
|
5
5
|
type ComponentType = typeof NsIcon;
|
|
@@ -7,7 +7,7 @@ type Story = StoryObj<ComponentType>;
|
|
|
7
7
|
type MetaStory = Meta<ComponentType>;
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
title: '
|
|
10
|
+
title: 'Icons/NsIcon',
|
|
11
11
|
component: NsIcon,
|
|
12
12
|
decorators: [withCenterDecorator],
|
|
13
13
|
argTypes: {
|
|
@@ -17,27 +17,32 @@ import Home from './icons/home';
|
|
|
17
17
|
import AlertErrorIcon from './icons/AlertErrorIcon';
|
|
18
18
|
import WarningIcon from './icons/WarningIcon';
|
|
19
19
|
import CloseIcon from './icons/CloseIcon';
|
|
20
|
+
import UserIcon from './icons/UserIcon';
|
|
21
|
+
import HamburgerIcon from './icons/HamburgerIcon';
|
|
20
22
|
|
|
21
23
|
const IconVariants = {
|
|
22
24
|
arrowDown: ArrowDown,
|
|
23
25
|
arrowUp: ArrowUp,
|
|
24
26
|
arrowLeft: ArrowLeft,
|
|
25
27
|
arrowRight: ArrowRight,
|
|
28
|
+
alertError: AlertErrorIcon,
|
|
26
29
|
cart: Cart,
|
|
27
30
|
cartBadge: CartBadge,
|
|
31
|
+
close: CloseIcon,
|
|
28
32
|
checkShield: CheckShield,
|
|
29
33
|
checkVerified: CheckVerified,
|
|
30
34
|
error: ErrorIcon,
|
|
35
|
+
hamburgerIcon: HamburgerIcon,
|
|
36
|
+
home: Home,
|
|
31
37
|
infoFilled: InfoFilled,
|
|
32
38
|
infoOutlined: InfoOutlined,
|
|
33
39
|
search: SearchIcon,
|
|
34
40
|
success: SuccessIcon,
|
|
35
|
-
trash: TrashIcon,
|
|
36
41
|
slash: SlashIcon,
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
trash: TrashIcon,
|
|
43
|
+
userIcon: UserIcon,
|
|
39
44
|
warning: WarningIcon,
|
|
40
|
-
close: CloseIcon
|
|
41
45
|
};
|
|
42
46
|
|
|
43
47
|
export default IconVariants;
|
|
48
|
+
export const isValidIconName = (name: string) => Object.keys(IconVariants).includes(name);
|
|
@@ -16,17 +16,26 @@ const AlertErrorIcon = (props: SvgIconProps) => {
|
|
|
16
16
|
xmlns="http://www.w3.org/2000/svg"
|
|
17
17
|
{...props}
|
|
18
18
|
>
|
|
19
|
-
<g id="
|
|
19
|
+
<g id="icon/alert/WarningFill-red" transform="translate(1.000000, 1.000000)">
|
|
20
20
|
<g id="Error2" transform="translate(0.000000, 1.200000)">
|
|
21
|
-
<path
|
|
21
|
+
<path
|
|
22
|
+
d="M17.9465423,14.8670135 L9.44311247,0.246687943 C9.35049358,0.100809118 9.18936767,0.012383152 9.01617259,0.012383152 C8.84297751,0.012383152 8.68185161,
|
|
22
23
|
0.100809118 8.58923271,0.246687943 L0.0706452929,14.8670135 C-0.0142965839,15.0216954 -0.0118890438,15.2093943 0.0769925071,15.3618609 C0.165874058,
|
|
23
24
|
15.5143276 0.328282319,15.6093523 0.505163987,15.6123832 L17.5120236,15.6123832 C17.6889052,15.6093523 17.8513135,15.5143276 17.940195,15.3618609 C18.0290766,
|
|
24
|
-
15.2093943 18.0314841,15.0216954 17.9465423,14.8670135 Z"
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
15.2093943 18.0314841,15.0216954 17.9465423,14.8670135 Z"
|
|
26
|
+
id="Shape"
|
|
27
|
+
fill={props.fill || '#B2140A'}
|
|
28
|
+
fillRule="nonzero"
|
|
29
|
+
></path>
|
|
30
|
+
<path
|
|
31
|
+
d="M8.19,12.84 C8.16437588,12.6281014 8.2368299,12.4160897 8.38677958,12.2641927 C8.53672927,12.1122956 8.74778837,12.0371121 8.96,12.06 C9.16715704,
|
|
27
32
|
12.0467652 9.37034806,12.1211477 9.52,12.265 C9.65709398,12.4241339 9.72701115,12.6303 9.715,12.84 C9.72048715,13.0522748 9.64341383,13.2584012 9.5,
|
|
28
33
|
13.415 C9.35312473,13.5641498 9.1489517,13.6425377 8.94,13.63 C8.72997224,13.6424095 8.52401376,13.5683367 8.37,13.425 C8.23531653,13.2613056 8.17063593,
|
|
29
|
-
13.0510936 8.19,12.84 Z M9.415,11.195 L8.5,11.195 L8.25,5.96 L9.675,5.96 L9.415,11.195 Z"
|
|
34
|
+
13.0510936 8.19,12.84 Z M9.415,11.195 L8.5,11.195 L8.25,5.96 L9.675,5.96 L9.415,11.195 Z"
|
|
35
|
+
id="Shape"
|
|
36
|
+
fill={props.fill || '#FFFFFF'}
|
|
37
|
+
fillRule="nonzero"
|
|
38
|
+
></path>
|
|
30
39
|
</g>
|
|
31
40
|
</g>
|
|
32
41
|
</SvgIcon>
|
|
@@ -4,38 +4,13 @@ import { SvgIconProps, SvgIcon } from '@mui/material';
|
|
|
4
4
|
|
|
5
5
|
const Cart = (props: SvgIconProps) => {
|
|
6
6
|
return (
|
|
7
|
-
<SvgIcon
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param props {fill: color to be filled for icon, color: color of the tick icon}
|
|
6
|
+
*/
|
|
7
|
+
const HamburgerIcon = (props: SvgIconProps) => {
|
|
8
|
+
return (
|
|
9
|
+
<SvgIcon viewBox="0 0 24 24" {...props} data-testid="hamburgerIcon" xmlns="http://www.w3.org/2000/svg">
|
|
10
|
+
<path
|
|
11
|
+
fillRule="evenodd"
|
|
12
|
+
clipRule="evenodd"
|
|
13
|
+
d="M0 1C0 0.447715 0.447715 0 1 0H19C19.5523 0 20 0.447715 20 1C20 1.55228 19.5523 2 19 2H1C0.447715 2 0 1.55228 0 1Z"
|
|
14
|
+
/>
|
|
15
|
+
<path
|
|
16
|
+
fillRule="evenodd"
|
|
17
|
+
clipRule="evenodd"
|
|
18
|
+
d="M0 9C0 8.44772 0.447715 8 1 8H19C19.5523 8 20 8.44772 20 9C20 9.55228 19.5523 10 19 10H1C0.447715 10 0 9.55228 0 9Z"
|
|
19
|
+
/>
|
|
20
|
+
<path
|
|
21
|
+
fillRule="evenodd"
|
|
22
|
+
clipRule="evenodd"
|
|
23
|
+
d="M0 17C0 16.4477 0.447715 16 1 16H19C19.5523 16 20 16.4477 20 17C20 17.5523 19.5523 18 19 18H1C0.447715 18 0 17.5523 0 17Z"
|
|
24
|
+
/>
|
|
25
|
+
</SvgIcon>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default HamburgerIcon;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import { useTheme } from '@mui/material/styles';
|
|
3
|
+
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param props {fill: color to be filled for icon, color: color of the tick icon}
|
|
7
|
+
*/
|
|
8
|
+
const UserIcon = (props: SvgIconProps) => {
|
|
9
|
+
const { palette } = useTheme();
|
|
10
|
+
const strokeColor = palette.primary.main;
|
|
11
|
+
return (
|
|
12
|
+
<SvgIcon viewBox="0 0 24 24" {...props} data-testid="userIcon" xmlns="http://www.w3.org/2000/svg">
|
|
13
|
+
<path
|
|
14
|
+
fillRule="evenodd"
|
|
15
|
+
clipRule="evenodd"
|
|
16
|
+
d="M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23Z"
|
|
17
|
+
stroke={strokeColor}
|
|
18
|
+
strokeWidth="2"
|
|
19
|
+
/>
|
|
20
|
+
<path
|
|
21
|
+
d="M19 20C18.9425 19.3229 19 17.5669 17.3793 17.2226C14.7126 16.6144 13.931 16.4078 14.1034 14.2272C15.8046 13.0796 15.7816 11.0252 15.7471 8.74139C15.7471 6.67508 14.0695 5 12 5C9.93052 5 8.25287 6.67508 8.25287 8.74139C8.25287 11.0367 8.25287 13.137 9.89655 14.2272C10.0575 16.4078 9.28736 16.6144 6.62069 17.2226C5 17.5669 5.05747 19.3229 5 20"
|
|
22
|
+
stroke={strokeColor}
|
|
23
|
+
strokeWidth="2"
|
|
24
|
+
strokeLinecap="round"
|
|
25
|
+
/>
|
|
26
|
+
</SvgIcon>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default UserIcon;
|
|
@@ -18,15 +18,24 @@ const WarningIcon = (props: SvgIconProps) => {
|
|
|
18
18
|
>
|
|
19
19
|
<g id="💎-icon/alert/WarningFill-yellow" transform="translate(1.000000, 1.000000)">
|
|
20
20
|
<g id="Warning2" transform="translate(0.000000, 1.200000)">
|
|
21
|
-
<path
|
|
21
|
+
<path
|
|
22
|
+
d="M17.9465423,14.8670135 L9.44311247,0.246687943 C9.35049358,0.100809118 9.18936767,0.012383152 9.01617259,0.012383152 C8.84297751,0.012383152 8.68185161,
|
|
22
23
|
0.100809118 8.58923271,0.246687943 L0.0706452929,14.8670135 C-0.0142965839,15.0216954 -0.0118890438,15.2093943 0.0769925071,15.3618609 C0.165874058,
|
|
23
24
|
15.5143276 0.328282319,15.6093523 0.505163987,15.6123832 L17.5120236,15.6123832 C17.6889052,15.6093523 17.8513135,15.5143276 17.940195,15.3618609 C18.0290766,
|
|
24
|
-
15.2093943 18.0314841,15.0216954 17.9465423,14.8670135 Z"
|
|
25
|
-
|
|
25
|
+
15.2093943 18.0314841,15.0216954 17.9465423,14.8670135 Z"
|
|
26
|
+
id="Shape"
|
|
27
|
+
fill="#FEBD00"
|
|
28
|
+
fillRule="nonzero"
|
|
29
|
+
></path>
|
|
30
|
+
<path
|
|
31
|
+
d="M8.19,12.84 C8.16437588,12.6281014 8.2368299,12.4160897 8.38677958,12.2641927 C8.53672927,12.1122956 8.74778837,12.0371121 8.96,12.06 C9.16715704,
|
|
26
32
|
12.0467652 9.37034806,12.1211477 9.52,12.265 C9.65709398,12.4241339 9.72701115,12.6303 9.715,12.84 C9.72048715,13.0522748 9.64341383,13.2584012 9.5,
|
|
27
33
|
13.415 C9.35312473,13.5641498 9.1489517,13.6425377 8.94,13.63 C8.72997224,13.6424095 8.52401376,13.5683367 8.37,13.425 C8.23531653,13.2613056 8.17063593,
|
|
28
|
-
13.0510936 8.19,12.84 Z M9.415,11.195 L8.5,11.195 L8.25,5.96 L9.675,5.96 L9.415,11.195 Z"
|
|
29
|
-
|
|
34
|
+
13.0510936 8.19,12.84 Z M9.415,11.195 L8.5,11.195 L8.25,5.96 L9.675,5.96 L9.415,11.195 Z"
|
|
35
|
+
id="Shape"
|
|
36
|
+
fill="#FFFFFF"
|
|
37
|
+
fillRule="nonzero"
|
|
38
|
+
></path>
|
|
30
39
|
</g>
|
|
31
40
|
</g>
|
|
32
41
|
</SvgIcon>
|
package/src/common/icon/index.ts
CHANGED
|
@@ -1,10 +1,60 @@
|
|
|
1
|
-
import { render, screen } from '
|
|
2
|
-
import NsImage from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { render, screen } from '@/test-utils/index';
|
|
2
|
+
import { NsImage } from '../';
|
|
3
|
+
|
|
4
|
+
describe('NsImage component', () => {
|
|
5
|
+
it('1. renders', () => {
|
|
6
|
+
const alt = 'test image';
|
|
7
|
+
render(<NsImage src="image.jpg" width={300} height={300} alt={alt} />);
|
|
8
|
+
const imgElement = screen.getByAltText(alt);
|
|
8
9
|
expect(imgElement).toBeInTheDocument();
|
|
9
10
|
});
|
|
11
|
+
|
|
12
|
+
it('2. renders with correct src and alt attributes', () => {
|
|
13
|
+
const src = 'image.jpg';
|
|
14
|
+
const alt = 'test image';
|
|
15
|
+
const { getByAltText } = render(<NsImage src={src} alt={alt} />);
|
|
16
|
+
const image = getByAltText(alt);
|
|
17
|
+
expect(image).toHaveAttribute('src', src);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('3. renders with width and height if variant is not provided', () => {
|
|
21
|
+
const { getByAltText } = render(<NsImage src="image.jpg" alt="test image" width={300} height={300} />);
|
|
22
|
+
const image = getByAltText('test image');
|
|
23
|
+
expect(image).toHaveAttribute('width', '300');
|
|
24
|
+
expect(image).toHaveAttribute('height', '300');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('4. renders with correct width and height based on variant', () => {
|
|
28
|
+
const { getByAltText } = render(<NsImage src="image.jpg" alt="test image" variant="icon" />);
|
|
29
|
+
const image = getByAltText('test image');
|
|
30
|
+
expect(image).toHaveAttribute('width', '60');
|
|
31
|
+
expect(image).toHaveAttribute('height', '60');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('5. renders with correct width and height if variant is "fill"', () => {
|
|
35
|
+
const { getByAltText } = render(<NsImage src="image.jpg" alt="test image" variant="fill" />);
|
|
36
|
+
const image = getByAltText('test image');
|
|
37
|
+
expect(image).toHaveAttribute('width', '100%');
|
|
38
|
+
expect(image).toHaveAttribute('height', 'auto');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('6. renders with correct width and height if variant is "award"', () => {
|
|
42
|
+
const { getByAltText } = render(<NsImage src="image.jpg" alt="test image" variant="award" />);
|
|
43
|
+
const image = getByAltText('test image');
|
|
44
|
+
expect(image).toHaveAttribute('width', '130');
|
|
45
|
+
expect(image).toHaveAttribute('height', '130');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('7. renders with correct width and height if variant is "product"', () => {
|
|
49
|
+
const { getByAltText } = render(<NsImage src="image.jpg" alt="test image" variant="product" />);
|
|
50
|
+
const image = getByAltText('test image');
|
|
51
|
+
expect(image).toHaveAttribute('width', '300');
|
|
52
|
+
expect(image).toHaveAttribute('height', '300');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('8. renders with additional props', () => {
|
|
56
|
+
const { getByAltText } = render(<NsImage src="image.jpg" alt="test image" className="custom-image" />);
|
|
57
|
+
const image = getByAltText('test image');
|
|
58
|
+
expect(image).toHaveClass('custom-image');
|
|
59
|
+
});
|
|
10
60
|
});
|