@nuskin/foundation-ui-components 1.0.0-cft-35.13 → 1.0.0-develop.10
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 +110 -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 +8 -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 +1 -1
- package/src/common/cart-icon/NsCartIcon.stories.tsx +2 -2
- package/src/common/cart-icon/NsCartIcon.tsx +1 -1
- package/src/common/cart-icon/index.ts +1 -1
- 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/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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NsIcon } from '../icon';
|
|
2
2
|
import { CartIconContainer, ItemCount } from './NsCartIcon.styled';
|
|
3
|
-
import { NsCartIconProps } from './types';
|
|
3
|
+
import { NsCartIconProps } from './types.d';
|
|
4
4
|
|
|
5
5
|
const NsCartIcon = ({ itemCount, size = 'large', color = 'primary' }: NsCartIconProps) => {
|
|
6
6
|
return (
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as NsCartIcon } from './NsCartIcon';
|
|
2
|
-
export type { NsCartIconProps } from './types';
|
|
2
|
+
export type { NsCartIconProps } from './types.d';
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
|
|
9
|
-
import { render, fireEvent, noop } from '
|
|
9
|
+
import { render, fireEvent, noop } from '@/test-utils/index';
|
|
10
10
|
import NsCheckbox from './NsCheckbox';
|
|
11
11
|
|
|
12
12
|
// Test suite for CustomCheckbox
|
|
@@ -54,4 +54,4 @@ describe('CustomCheckbox', () => {
|
|
|
54
54
|
// Assert that the handleChange function has been called
|
|
55
55
|
expect(handleChange).toHaveBeenCalled();
|
|
56
56
|
});
|
|
57
|
-
});
|
|
57
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { within } from '@testing-library/react';
|
|
3
|
-
import { withCenterDecorator } from '
|
|
3
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
4
4
|
import type { StoryObj, Meta } from '@storybook/react';
|
|
5
5
|
import { expect } from '@storybook/jest';
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ type MetaStory = Meta<ComponentType>;
|
|
|
13
13
|
const labelText = 'Checkbox Label';
|
|
14
14
|
// In this case, we're only passing the label prop.
|
|
15
15
|
export default {
|
|
16
|
-
title: 'Components/NsCheckbox',
|
|
16
|
+
title: 'Components/Inputs/NsCheckbox',
|
|
17
17
|
component: NsCheckbox,
|
|
18
18
|
decorators: [withCenterDecorator],
|
|
19
19
|
argTypes: {
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @author [vijayaprathap Kumar] (vpkumar@nuskin.com)
|
|
3
|
-
* checkbox.tsx
|
|
4
3
|
* @description Styled Components for Checkbox
|
|
5
4
|
*/
|
|
6
5
|
import DoneIcon from '@mui/icons-material/Done';
|
|
7
6
|
|
|
8
|
-
import { styled } from '@nuskin/foundation-theme';
|
|
7
|
+
import { styled, ColorUtils } from '@nuskin/foundation-theme';
|
|
9
8
|
import { NsFlag } from '../flag';
|
|
10
|
-
|
|
9
|
+
const { paletteColor, buttonColor } = ColorUtils;
|
|
11
10
|
/**
|
|
12
11
|
* Wrapper BpIcon for checkbox.tsx
|
|
13
12
|
* @params ( theme: { palette }) / Provide the color's to contaier from @nuskin/foundation-theme
|
|
14
13
|
*/
|
|
15
14
|
|
|
16
|
-
export const BpIcon = styled(DoneIcon)(({ theme
|
|
15
|
+
export const BpIcon = styled(DoneIcon)(({ theme }) => ({
|
|
17
16
|
border: '1px solid #8C8C8C',
|
|
18
17
|
path: {
|
|
19
18
|
display: 'none',
|
|
@@ -25,31 +24,31 @@ export const BpIcon = styled(DoneIcon)(({ theme: { palette } }) => ({
|
|
|
25
24
|
outline: '3px solid #94D6E9',
|
|
26
25
|
},
|
|
27
26
|
'input:disabled ~ &': {
|
|
28
|
-
background:
|
|
27
|
+
background: buttonColor('primary', 'hovered')({ theme }),
|
|
29
28
|
},
|
|
30
29
|
}));
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
32
|
* Wrapper BpCheckedIcon for checkbox.tsx
|
|
34
|
-
* @params ( theme: { palette }) / Provide the color's to
|
|
33
|
+
* @params ( theme: { palette }) / Provide the color's to container from @nuskin/foundation-theme
|
|
35
34
|
*/
|
|
36
35
|
|
|
37
|
-
export const BpCheckedIcon = styled(BpIcon)(({ theme
|
|
36
|
+
export const BpCheckedIcon = styled(BpIcon)(({ theme }) => ({
|
|
38
37
|
path: {
|
|
39
38
|
display: 'block',
|
|
40
39
|
},
|
|
41
|
-
background:
|
|
42
|
-
color:
|
|
40
|
+
background: paletteColor('primary', 'main')({ theme }),
|
|
41
|
+
color: paletteColor('primary', 'contrastText')({ theme }),
|
|
43
42
|
}));
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
${({ $hasDisabled, theme: { palette } }) =>
|
|
47
|
-
$hasDisabled &&
|
|
48
|
-
`
|
|
49
|
-
color: ${palette?.primary?.buttonState?.hovered};
|
|
50
|
-
`}
|
|
51
|
-
`;
|
|
44
|
+
const getLabelColor = (isDisabled: boolean, color: string) => (!isDisabled ? '' : `color: ${color}`);
|
|
52
45
|
|
|
46
|
+
export const StyledLabel = styled('span')<{ isDisabled: boolean }>`
|
|
47
|
+
${({ isDisabled, theme }) => {
|
|
48
|
+
const color = buttonColor('primary', 'hovered')({ theme });
|
|
49
|
+
return getLabelColor(isDisabled, color);
|
|
50
|
+
}}
|
|
51
|
+
`;
|
|
53
52
|
export const StyledFlagLabel = styled(NsFlag)`
|
|
54
53
|
margin-right: 16px;
|
|
55
54
|
`;
|
|
@@ -9,7 +9,7 @@ import FormControlLabel from '@mui/material/FormControlLabel';
|
|
|
9
9
|
import { default as MUICheckbox } from '@mui/material/Checkbox';
|
|
10
10
|
|
|
11
11
|
import { BpCheckedIcon, BpIcon, StyledLabel, StyledFlagLabel } from './NsCheckbox.styled';
|
|
12
|
-
import { NsCheckboxProps } from './types';
|
|
12
|
+
import { NsCheckboxProps } from './types.d';
|
|
13
13
|
|
|
14
14
|
import { NsTypography } from '../';
|
|
15
15
|
|
|
@@ -54,7 +54,7 @@ const NsCheckbox = (props: PropsWithChildren<NsCheckboxProps>) => {
|
|
|
54
54
|
() => (
|
|
55
55
|
<NsTypography variant="p-l">
|
|
56
56
|
<StyledFlagLabel {...flag} size={size} testId={`${name}-flag-label`} />
|
|
57
|
-
<StyledLabel className="checkbox-label-text"
|
|
57
|
+
<StyledLabel className="checkbox-label-text" isDisabled={disabled}>
|
|
58
58
|
{label}
|
|
59
59
|
</StyledLabel>
|
|
60
60
|
</NsTypography>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as NsCheckbox } from './NsCheckbox';
|
|
2
|
-
export type { NsCheckboxProps } from './types';
|
|
2
|
+
export type { NsCheckboxProps } from './types.d';
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author [vijayaprathap Kumar] (vpkumar@nuskin.com)
|
|
3
|
-
* types.d.ts
|
|
4
|
-
* @description NsCheckbox Props extending Mui CheckboxProps interface.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
1
|
import { CheckboxProps as MUICheckboxProps } from '@material-ui/core/Checkbox';
|
|
8
2
|
|
|
9
3
|
import { NsFlagProps } from '../flag';
|
|
10
4
|
|
|
11
5
|
// Define the props for the custom checkbox component
|
|
12
|
-
export type NsCheckboxProps = Pick<MUICheckboxProps, 'label' | 'onChange'
|
|
6
|
+
export type NsCheckboxProps = Partial<Pick<MUICheckboxProps, 'label' | 'onChange'>> & {
|
|
13
7
|
name: string;
|
|
14
8
|
className?: string;
|
|
15
9
|
checked: boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { Box } from '@mui/material';
|
|
3
3
|
import { styled } from '@nuskin/foundation-theme';
|
|
4
|
-
import { NsColumnControlProps, sizeObjectType } from './types';
|
|
4
|
+
import { NsColumnControlProps, sizeObjectType } from './types.d';
|
|
5
5
|
import { getColumnSizes } from './utils';
|
|
6
6
|
|
|
7
7
|
const options = {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { getColumnSizes } from './utils';
|
|
3
|
+
import { StyledFlex } from './styled/StyledFlex';
|
|
4
|
+
import { NsFlexColumnsProps } from './types';
|
|
5
|
+
|
|
6
|
+
const NsFlexColumns = ({ columnClass, children, gap, additionalProps, isFullWidth }: NsFlexColumnsProps) => {
|
|
7
|
+
const sizes = useMemo(() => {
|
|
8
|
+
return getColumnSizes(columnClass ?? 'ns-col-lg-1-1');
|
|
9
|
+
}, [columnClass]);
|
|
10
|
+
return (
|
|
11
|
+
<StyledFlex
|
|
12
|
+
isFullWidth={isFullWidth || false}
|
|
13
|
+
gap={gap}
|
|
14
|
+
sizes={sizes}
|
|
15
|
+
className="ns-flex-columns"
|
|
16
|
+
data-testid={additionalProps?.testid ?? 'ns-flex-columns'}
|
|
17
|
+
>
|
|
18
|
+
{children}
|
|
19
|
+
</StyledFlex>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
export default NsFlexColumns;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { getColumnSizes } from './utils';
|
|
3
|
+
import { StyledGrid } from './styled/StyledGrid';
|
|
4
|
+
import { NsGridColumnsProps } from './types';
|
|
5
|
+
|
|
6
|
+
const NsGridColumns = ({ columnClass, children, gap, isFullWidth, additionalProps }: NsGridColumnsProps) => {
|
|
7
|
+
const sizes = useMemo(() => {
|
|
8
|
+
return getColumnSizes(columnClass ?? 'ns-col-lg-1-1');
|
|
9
|
+
}, [columnClass]);
|
|
10
|
+
return (
|
|
11
|
+
<StyledGrid
|
|
12
|
+
isFullWidth={isFullWidth || false}
|
|
13
|
+
gap={gap}
|
|
14
|
+
sizes={sizes}
|
|
15
|
+
className="ns-grid-columns"
|
|
16
|
+
data-testid={additionalProps?.testid ?? 'ns-grid-columns'}
|
|
17
|
+
>
|
|
18
|
+
{children}
|
|
19
|
+
</StyledGrid>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
export default NsGridColumns;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { default as NsColumnControl } from './NsColumnControl';
|
|
2
|
-
export
|
|
2
|
+
export { default as NsFlexColumns } from './NsFlexColumns';
|
|
3
|
+
export { default as NsGridColumns } from './NsGridColumns';
|
|
4
|
+
export type { NsColumnControlProps } from './types.d';
|
package/src/common/column-control/{NsColumnControl.spec.tsx → specs/NsColumnControl.spec.tsx}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { DivArray } from '
|
|
1
|
+
import { NsColumnControl } from '@/common/index';
|
|
2
|
+
import { render, screen } from '@/test-utils/index';
|
|
3
|
+
import { DivArray } from '../stories/DivArray';
|
|
4
4
|
|
|
5
5
|
describe('NsColumnControl component', () => {
|
|
6
6
|
it('renders an column with proper grid value for tablet', () => {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { render, screen } from '../../../../test-utils';
|
|
2
|
+
import { NsFlexColumns } from '@/common/index';
|
|
3
|
+
import { DivArray } from '../stories/DivArray';
|
|
4
|
+
|
|
5
|
+
describe('NsFlexColumns component', () => {
|
|
6
|
+
it('renders an column with proper grid value for tablet', () => {
|
|
7
|
+
render(
|
|
8
|
+
<NsFlexColumns columnClass="ns-col-lg-1-1-1" gap={16}>
|
|
9
|
+
<DivArray elementsCount={4} />
|
|
10
|
+
</NsFlexColumns>
|
|
11
|
+
);
|
|
12
|
+
const element = screen.getByTestId('ns-flex-columns');
|
|
13
|
+
expect(element).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
it('renders an column with proper grid value', () => {
|
|
16
|
+
console.warn = jest.fn();
|
|
17
|
+
render(
|
|
18
|
+
<NsFlexColumns columnClass="" gap={16}>
|
|
19
|
+
<DivArray elementsCount={4} />
|
|
20
|
+
</NsFlexColumns>
|
|
21
|
+
);
|
|
22
|
+
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining('Received invalid className'));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { render, screen } from '../../../../test-utils';
|
|
2
|
+
import { NsGridColumns } from '@/common/index';
|
|
3
|
+
import { DivArray } from '../stories/DivArray';
|
|
4
|
+
|
|
5
|
+
describe('NsGridColumns component', () => {
|
|
6
|
+
it('renders an column with proper grid value for tablet', () => {
|
|
7
|
+
render(
|
|
8
|
+
<NsGridColumns columnClass="ns-col-lg-1-1-1" gap={16}>
|
|
9
|
+
<DivArray elementsCount={4} />
|
|
10
|
+
</NsGridColumns>
|
|
11
|
+
);
|
|
12
|
+
const element = screen.getByTestId('ns-grid-columns');
|
|
13
|
+
expect(element).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
it('renders an column with proper grid value', () => {
|
|
16
|
+
console.warn = jest.fn();
|
|
17
|
+
render(
|
|
18
|
+
<NsGridColumns columnClass="" gap={16}>
|
|
19
|
+
<DivArray elementsCount={4} />
|
|
20
|
+
</NsGridColumns>
|
|
21
|
+
);
|
|
22
|
+
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining('Received invalid className'));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
|
+
import {DivArray} from './DivArray';
|
|
4
|
+
|
|
5
|
+
type ComponentType = typeof DivArray;
|
|
6
|
+
type Story = StoryObj<ComponentType>;
|
|
7
|
+
type MetaStory = Meta<ComponentType>;
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: 'Components/Data Display/Column/NDivs',
|
|
11
|
+
component: DivArray,
|
|
12
|
+
decorators: [withCenterDecorator],
|
|
13
|
+
args: {
|
|
14
|
+
elementsCount: 2,
|
|
15
|
+
},
|
|
16
|
+
} as MetaStory;
|
|
17
|
+
|
|
18
|
+
export const Basic: Story = {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
type DivArrayProps = {
|
|
4
|
+
elementsCount: number;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const getRandom = (n: number) => (Math.random() * n).toFixed(0);
|
|
8
|
+
|
|
9
|
+
type DivComponentProps = PropsWithChildren<{ style: Record<string, any>; index: number }>;
|
|
10
|
+
export const DivComponent = ({ style, index, children }: DivComponentProps) => {
|
|
11
|
+
const borderWidth = `${getRandom(5)}px`;
|
|
12
|
+
const padding = `${getRandom(20)}px`;
|
|
13
|
+
return (
|
|
14
|
+
<div
|
|
15
|
+
style={{
|
|
16
|
+
padding,
|
|
17
|
+
border: `${borderWidth} solid`,
|
|
18
|
+
borderColor: `hsl(${getRandom(359)},100%, 50%)`,
|
|
19
|
+
background: `hsla(${getRandom(359)},100%, 50%,0.3)`,
|
|
20
|
+
...style,
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
{index}
|
|
24
|
+
{children}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* this component return a fragment containing n number of div, with each div numbered as per its index
|
|
30
|
+
* @param n: number of div to render
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export const DivArray = ({ elementsCount }: DivArrayProps) => (
|
|
34
|
+
<>
|
|
35
|
+
{Array(elementsCount)
|
|
36
|
+
.fill(0)
|
|
37
|
+
.map((_, index) => (
|
|
38
|
+
<DivComponent key={index} index={index + 1} style={{}} />
|
|
39
|
+
))}
|
|
40
|
+
</>
|
|
41
|
+
);
|
|
42
|
+
export const DivArrayRandom = ({ elementsCount }: DivArrayProps) => (
|
|
43
|
+
<>
|
|
44
|
+
{Array(elementsCount)
|
|
45
|
+
.fill(0)
|
|
46
|
+
.map((_, index) => {
|
|
47
|
+
const width = `${getRandom(700)}px`;
|
|
48
|
+
const height = `${getRandom(400)}px`;
|
|
49
|
+
return (
|
|
50
|
+
<DivComponent
|
|
51
|
+
key={index}
|
|
52
|
+
index={index + 1}
|
|
53
|
+
style={{
|
|
54
|
+
width,
|
|
55
|
+
height,
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
item no = {index + 1} with width = {width} and height = {height}
|
|
59
|
+
</DivComponent>
|
|
60
|
+
);
|
|
61
|
+
})}
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
-
import { withCenterDecorator } from '
|
|
3
|
-
import { NsColumnControl } from '
|
|
4
|
-
import { DivArray } from './
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
|
+
import { NsColumnControl } from '@/common/index';
|
|
4
|
+
import { DivArray } from './DivArray';
|
|
5
|
+
import { childrenMapping, selectDivOptions } from './common';
|
|
5
6
|
|
|
6
7
|
type ComponentType = typeof NsColumnControl;
|
|
7
8
|
type Story = StoryObj<ComponentType>;
|
|
8
9
|
type MetaStory = Meta<ComponentType>;
|
|
9
10
|
|
|
10
|
-
/* an array from 1 to n */
|
|
11
|
-
const selectDivOptions = Array(16)
|
|
12
|
-
.fill(0)
|
|
13
|
-
.map((e, i) => i + 1);
|
|
14
|
-
const childrenMapping = selectDivOptions.reduce((a, c) => {
|
|
15
|
-
return {
|
|
16
|
-
...a,
|
|
17
|
-
[c]: <DivArray elementsCount={c} />,
|
|
18
|
-
};
|
|
19
|
-
}, {});
|
|
20
|
-
|
|
21
11
|
export default {
|
|
22
|
-
title: 'Components/NsColumnControl',
|
|
12
|
+
title: 'Components/Data Display/Column/NsColumnControl',
|
|
23
13
|
component: NsColumnControl,
|
|
24
14
|
decorators: [withCenterDecorator],
|
|
25
15
|
argTypes: {
|
|
@@ -42,7 +32,10 @@ export default {
|
|
|
42
32
|
},
|
|
43
33
|
} as MetaStory;
|
|
44
34
|
|
|
45
|
-
export const
|
|
35
|
+
export const ResponsiveColumnControl: Story = {};
|
|
36
|
+
export const SingleColumnControl: Story = {
|
|
37
|
+
args: { columnClass: '' },
|
|
38
|
+
};
|
|
46
39
|
export const TwoColumn11: Story = {
|
|
47
40
|
args: { columnClass: 'ns-col-lg-1-1' },
|
|
48
41
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
|
+
import { NsFlexColumns } from '..';
|
|
4
|
+
import { DivArray, DivArrayRandom } from './DivArray';
|
|
5
|
+
import { childrenMapping, selectDivOptions } from './common';
|
|
6
|
+
|
|
7
|
+
type ComponentType = typeof NsFlexColumns;
|
|
8
|
+
type Story = StoryObj<ComponentType>;
|
|
9
|
+
type MetaStory = Meta<ComponentType>;
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Components/Data Display/Column/NsFlexColumns',
|
|
13
|
+
component: NsFlexColumns,
|
|
14
|
+
decorators: [withCenterDecorator],
|
|
15
|
+
argTypes: {
|
|
16
|
+
columnClass: {
|
|
17
|
+
control: 'text',
|
|
18
|
+
defaultValue: 'ns-col-lg-1-1-1 ns-col-md-1-1 ns-col-sm-1',
|
|
19
|
+
},
|
|
20
|
+
gap: {
|
|
21
|
+
control: 'number',
|
|
22
|
+
defaultValue: 16,
|
|
23
|
+
},
|
|
24
|
+
children: {
|
|
25
|
+
control: {
|
|
26
|
+
type: 'select',
|
|
27
|
+
options: selectDivOptions,
|
|
28
|
+
},
|
|
29
|
+
defaultValue: <DivArrayRandom elementsCount={8} />,
|
|
30
|
+
mapping: childrenMapping,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
args: {
|
|
34
|
+
columnClass: '',
|
|
35
|
+
children: <DivArrayRandom elementsCount={12} />,
|
|
36
|
+
},
|
|
37
|
+
} as MetaStory;
|
|
38
|
+
|
|
39
|
+
export const DefaultColumnControl: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
children: <DivArray elementsCount={8} />,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
export const TwoColumn11: Story = {
|
|
45
|
+
args: { columnClass: 'ns-col-lg-1-1' },
|
|
46
|
+
};
|
|
47
|
+
export const TwoColumn21: Story = {
|
|
48
|
+
args: { columnClass: 'ns-col-lg-2-1' },
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const ThreeColumn211: Story = {
|
|
52
|
+
args: { columnClass: 'ns-col-lg-2-1-1' },
|
|
53
|
+
};
|
|
54
|
+
export const ThreeColumn121: Story = {
|
|
55
|
+
args: { columnClass: 'ns-col-lg-1-2-1' },
|
|
56
|
+
};
|
|
57
|
+
export const ThreeColumn111: Story = {
|
|
58
|
+
args: { columnClass: 'ns-col-lg-1-1-1' },
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const FourColumn1111: Story = {
|
|
62
|
+
args: { columnClass: 'ns-col-lg-1-1-1-1' },
|
|
63
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
|
+
import { NsGridColumns } from '..';
|
|
4
|
+
import { DivArray, DivArrayRandom } from './DivArray';
|
|
5
|
+
import { childrenMapping, selectDivOptions } from './common';
|
|
6
|
+
|
|
7
|
+
type ComponentType = typeof NsGridColumns;
|
|
8
|
+
type Story = StoryObj<ComponentType>;
|
|
9
|
+
type MetaStory = Meta<ComponentType>;
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Components/Data Display/Column/NsGridColumns',
|
|
13
|
+
component: NsGridColumns,
|
|
14
|
+
decorators: [withCenterDecorator],
|
|
15
|
+
argTypes: {
|
|
16
|
+
columnClass: {
|
|
17
|
+
control: 'text',
|
|
18
|
+
defaultValue: 'ns-col-lg-1-1-1 ns-col-md-1-1 ns-col-sm-1',
|
|
19
|
+
},
|
|
20
|
+
gap: {
|
|
21
|
+
control: 'number',
|
|
22
|
+
defaultValue: 16,
|
|
23
|
+
},
|
|
24
|
+
children: {
|
|
25
|
+
control: {
|
|
26
|
+
type: 'select',
|
|
27
|
+
options: selectDivOptions,
|
|
28
|
+
},
|
|
29
|
+
defaultValue: <DivArrayRandom elementsCount={8} />,
|
|
30
|
+
mapping: childrenMapping,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
args: {
|
|
34
|
+
columnClass: '',
|
|
35
|
+
children: <DivArrayRandom elementsCount={12} />,
|
|
36
|
+
},
|
|
37
|
+
} as MetaStory;
|
|
38
|
+
|
|
39
|
+
export const DefaultColumnControl: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
children: <DivArray elementsCount={8} />,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
export const TwoColumn11: Story = {
|
|
45
|
+
args: { columnClass: 'ns-col-lg-1-1' },
|
|
46
|
+
};
|
|
47
|
+
export const TwoColumn21: Story = {
|
|
48
|
+
args: { columnClass: 'ns-col-lg-2-1' },
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const ThreeColumn211: Story = {
|
|
52
|
+
args: { columnClass: 'ns-col-lg-2-1-1' },
|
|
53
|
+
};
|
|
54
|
+
export const ThreeColumn121: Story = {
|
|
55
|
+
args: { columnClass: 'ns-col-lg-1-2-1' },
|
|
56
|
+
};
|
|
57
|
+
export const ThreeColumn111: Story = {
|
|
58
|
+
args: { columnClass: 'ns-col-lg-1-1-1' },
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const FourColumn1111: Story = {
|
|
62
|
+
args: { columnClass: 'ns-col-lg-1-1-1-1' },
|
|
63
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DivArray } from './DivArray';
|
|
2
|
+
|
|
3
|
+
/* an array from 1 to n */
|
|
4
|
+
export const selectDivOptions = Array(16)
|
|
5
|
+
.fill(0)
|
|
6
|
+
.map((_, index) => index + 1);
|
|
7
|
+
|
|
8
|
+
/* this component is used only as a utility to show column control in storybook */
|
|
9
|
+
export const childrenMapping = selectDivOptions.reduce((childrenMappingObject, elementCount) => {
|
|
10
|
+
return {
|
|
11
|
+
...childrenMappingObject,
|
|
12
|
+
[elementCount]: <DivArray elementsCount={elementCount} />,
|
|
13
|
+
};
|
|
14
|
+
}, {});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Box } from '@mui/material';
|
|
2
|
+
import { styled } from '@nuskin/foundation-theme';
|
|
3
|
+
import { sizeObjectType } from '../types';
|
|
4
|
+
import { commonStyles, getPercentArray } from './common';
|
|
5
|
+
|
|
6
|
+
const options = {
|
|
7
|
+
shouldForwardProp: (propKey: string) => !['sizes', 'gap', 'isFullWidth'].includes(propKey),
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type StyledFlexProps = {
|
|
11
|
+
sizes: sizeObjectType;
|
|
12
|
+
gap?: number;
|
|
13
|
+
isFullWidth: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/* main wrapper for column control using css flex */
|
|
17
|
+
export const StyledFlex = styled(
|
|
18
|
+
Box as any,
|
|
19
|
+
options
|
|
20
|
+
)<StyledFlexProps>(({ sizes, gap, isFullWidth }: StyledFlexProps) => {
|
|
21
|
+
const gridGap = gap ? `${gap}px` : '2rem';
|
|
22
|
+
const fraction = getPercentArray(sizes.fractions);
|
|
23
|
+
const flexResponsive = { flexGrow: 1, flexShrink: 1 };
|
|
24
|
+
const maxWidth = isFullWidth ? '100%' : '1200px';
|
|
25
|
+
const style: any = {
|
|
26
|
+
gap: gridGap,
|
|
27
|
+
...commonStyles,
|
|
28
|
+
maxWidth,
|
|
29
|
+
display: 'flex',
|
|
30
|
+
paddingInline: '20px',
|
|
31
|
+
flexWrap: 'wrap',
|
|
32
|
+
justifyContent: 'center',
|
|
33
|
+
'> *': {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
minWidth: '220px',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
fraction.forEach((f, i) => {
|
|
39
|
+
style[`> :nth-of-type(${fraction.length}n+${i + 1})`] = {
|
|
40
|
+
flexBasis: `calc(${fraction[i]} - ${gridGap})`,
|
|
41
|
+
...flexResponsive,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
return style;
|
|
45
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Box } from '@mui/material';
|
|
2
|
+
import { styled } from '@nuskin/foundation-theme';
|
|
3
|
+
import { sizeObjectType } from '../types';
|
|
4
|
+
import { commonStyles, getPercentArray } from './common';
|
|
5
|
+
|
|
6
|
+
type StyledGridProps = {
|
|
7
|
+
sizes: sizeObjectType;
|
|
8
|
+
gap?: number;
|
|
9
|
+
isFullWidth: boolean;
|
|
10
|
+
};
|
|
11
|
+
const options = {
|
|
12
|
+
shouldForwardProp: (propKey: string) => !['sizes', 'gap', 'isFullWidth'].includes(propKey),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/* main wrapper for column control using css grid */
|
|
16
|
+
export const StyledGrid = styled(
|
|
17
|
+
Box as any,
|
|
18
|
+
options
|
|
19
|
+
)<StyledGridProps>(({ sizes, gap, isFullWidth }: StyledGridProps) => {
|
|
20
|
+
const gridGap = gap ?? '2rem';
|
|
21
|
+
const maxWidth = isFullWidth ? '100%' : '1200px';
|
|
22
|
+
return {
|
|
23
|
+
gap: gridGap,
|
|
24
|
+
...commonStyles,
|
|
25
|
+
maxWidth,
|
|
26
|
+
display: 'grid',
|
|
27
|
+
/* here we are creating gridTemplateColumns as calc(40% - 20px) calc(40% - 20px), */
|
|
28
|
+
gridTemplateColumns: getPercentArray(sizes.fractions)
|
|
29
|
+
?.map((fractionPercent) => `calc(${fractionPercent} - 20px)`)
|
|
30
|
+
.join(''),
|
|
31
|
+
justifyContent: 'center',
|
|
32
|
+
'> *': {
|
|
33
|
+
minWidth: '220px',
|
|
34
|
+
width: 'auto !important',
|
|
35
|
+
},
|
|
36
|
+
'.span-2': {
|
|
37
|
+
gridColumn: 'span 2',
|
|
38
|
+
},
|
|
39
|
+
} as any;
|
|
40
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const mobileBreakPoint = '600px';
|
|
2
|
+
|
|
3
|
+
export const commonStyles = {
|
|
4
|
+
margin: '32px auto',
|
|
5
|
+
|
|
6
|
+
[`@media (max-width: ${mobileBreakPoint})`]: {
|
|
7
|
+
display: 'flex',
|
|
8
|
+
flexDirection: 'column',
|
|
9
|
+
flexWrap: 'wrap',
|
|
10
|
+
margin: '2rem 1rem',
|
|
11
|
+
'> * ': {
|
|
12
|
+
flex: '1 1 0 !important',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
/*
|
|
17
|
+
we have kept extra margin by taking 80% instead of 100%, because margins and padding,
|
|
18
|
+
and gaps also take up space, so we should be left with appropriate space
|
|
19
|
+
example:
|
|
20
|
+
['1','1'] => ['40%','40%']
|
|
21
|
+
['1','2'] => ['27%','53%']
|
|
22
|
+
*/
|
|
23
|
+
export function getPercentArray(fractionArray?: string[] | number[]) {
|
|
24
|
+
const numbers = fractionArray?.map((numberString) => +numberString)?.filter((num) => 0 < num && num < 10) ?? [];
|
|
25
|
+
const sum = numbers.reduce((currentSum, currentNumber) => currentSum + currentNumber, 0);
|
|
26
|
+
return numbers.map((currentNumber) => ((currentNumber / sum) * 80).toFixed(2) + '%');
|
|
27
|
+
}
|