@mrshmllw/smores-react 9.1.4 → 9.2.0

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.
@@ -0,0 +1,35 @@
1
+ /// <reference types="react" />
2
+ import { Color } from '../theme';
3
+ export type SegmentedControlOption<T = string | number> = {
4
+ label: string;
5
+ /** value needs to be number or string */
6
+ value: T;
7
+ /** optional tag able to show in the toggle if showTag prop is passed */
8
+ tag?: string;
9
+ isDisabled?: boolean;
10
+ };
11
+ type StylingOptions = {
12
+ toggle?: Color;
13
+ background?: Color;
14
+ text?: Color;
15
+ selectedText?: Color;
16
+ tagBg?: Color;
17
+ tagBorder?: Color;
18
+ tagText?: Color;
19
+ };
20
+ export type SegmentedControlProps<T> = {
21
+ /** you can pass more than 2 options */
22
+ options: SegmentedControlOption<T>[];
23
+ value: T;
24
+ onChange: (value: T) => void;
25
+ /** pass this prop if you want to show the tag in the toggle */
26
+ showTag?: boolean;
27
+ /** pass a StylingOptions object with the needed styles if you want to style the SegmentedControl */
28
+ styles?: StylingOptions;
29
+ };
30
+ /**
31
+ * ### How do I pass state to the `SegmentedControl` component?
32
+ * We recommend pulling the state up to at least the component that renders `SegmentedControl` up to at least the component that renders `SegmentedControl`, this should make it easier to pass state to the `SegmentedControl` component
33
+ */
34
+ export declare const SegmentedControl: <T>({ options, value, onChange, showTag, styles: { tagBorder, tagText, tagBg, selectedText, text, background, toggle, }, }: SegmentedControlProps<T>) => JSX.Element;
35
+ export {};
@@ -0,0 +1,59 @@
1
+ import styled from 'styled-components';
2
+ import { theme } from '../theme';
3
+ import { Box } from '../Box';
4
+ import { Tag } from '../Tag';
5
+ import { Text } from '../Text';
6
+ import React from 'react';
7
+ import { ToggleButton } from './ToggleButton';
8
+ /**
9
+ * ### How do I pass state to the `SegmentedControl` component?
10
+ * We recommend pulling the state up to at least the component that renders `SegmentedControl` up to at least the component that renders `SegmentedControl`, this should make it easier to pass state to the `SegmentedControl` component
11
+ */
12
+ export const SegmentedControl = ({ options, value, onChange, showTag, styles: { tagBorder = 'marshmallowPink', tagText = 'cream', tagBg = 'marshmallowPink', selectedText = 'cream', text = 'liquorice', background, toggle, } = {}, }) => {
13
+ return (React.createElement(ToggleWrapper, { backgroundColor: background },
14
+ React.createElement(IndicatorWrapper, { backgroundColor: background },
15
+ options.map((option) => {
16
+ return (React.createElement(ToggleButton, { key: option.label, name: "toggle-version-button", value: option.value, onChange: onChange, isSelected: option.value === value, isDisabled: option.isDisabled },
17
+ React.createElement(StyledWrapper, null,
18
+ showTag && option.tag && (React.createElement(StyledTag, { bgColor: tagBg, borderColor: tagBorder, color: tagText, label: option.tag })),
19
+ React.createElement(StyledText, { isSelected: option.value === value, selectedTextColor: selectedText, color: text }, option.label))));
20
+ }),
21
+ React.createElement(ToggleIndicator, { selectedIndex: options.findIndex((option) => option.value === value), sections: options.length, toggleColor: toggle }))));
22
+ };
23
+ const BORDER_RADIUS = 25;
24
+ const StyledWrapper = styled(Box) `
25
+ display: flex;
26
+ justify-content: center;
27
+ align-items: center;
28
+ gap: 4px;
29
+ `;
30
+ const StyledTag = styled(Tag) `
31
+ border-radius: 100px;
32
+ `;
33
+ const StyledText = styled(Text) `
34
+ font-weight: ${theme.font.weight.medium};
35
+ ${({ isSelected, selectedTextColor }) => isSelected && `color: ${theme.colors[selectedTextColor]};`}
36
+ padding: 2px 0px;
37
+ `;
38
+ const ToggleWrapper = styled(Box) `
39
+ padding: 4px;
40
+ background-color: ${(p) => theme.colors[p.backgroundColor ?? 'custard']};
41
+ border-radius: ${BORDER_RADIUS}px;
42
+ `;
43
+ const IndicatorWrapper = styled(Box) `
44
+ position: relative;
45
+ display: flex;
46
+ background-color: ${(p) => theme.colors[p.backgroundColor ?? 'custard']};
47
+ border-radius: ${BORDER_RADIUS}px;
48
+ `;
49
+ const ToggleIndicator = styled(Box) `
50
+ background-color: ${(p) => theme.colors[p.toggleColor ?? 'liquorice']};
51
+ border-radius: ${BORDER_RADIUS}px;
52
+ position: absolute;
53
+ z-index: 1;
54
+ height: 100%;
55
+ width: ${(p) => `calc(100% / ${p.sections})`};
56
+ transition: transform 0.4s;
57
+ transform: ${(p) => `translateX(${p.selectedIndex * 100}%)`};
58
+ `;
59
+ //# sourceMappingURL=SegmentedControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SegmentedControl.js","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAS,KAAK,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAgC7C;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAK,EACnC,OAAO,EACP,KAAK,EACL,QAAQ,EACR,OAAO,EACP,MAAM,EAAE,EACN,SAAS,GAAG,iBAAiB,EAC7B,OAAO,GAAG,OAAO,EACjB,KAAK,GAAG,iBAAiB,EACzB,YAAY,GAAG,OAAO,EACtB,IAAI,GAAG,WAAW,EAClB,UAAU,EACV,MAAM,GACP,GAAG,EAAE,GACmB,EAAE,EAAE;IAC7B,OAAO,CACL,oBAAC,aAAa,IAAC,eAAe,EAAE,UAAU;QACxC,oBAAC,gBAAgB,IAAC,eAAe,EAAE,UAAU;YAC1C,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;gBACtB,OAAO,CACL,oBAAC,YAAY,IACX,GAAG,EAAE,MAAM,CAAC,KAAK,EACjB,IAAI,EAAC,uBAAuB,EAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,QAAQ,EAAE,QAAQ,EAClB,UAAU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C,eAAe,IAAI,SAAS,CAAC;mBACtD,aAAa;CAC/B,CAAA;AAED,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,CAA6B;;;sBAG3C,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,IAAI,SAAS,CAAC;mBACtD,aAAa;CAC/B,CAAA;AAED,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,CAIjC;sBACoB,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,IAAI,WAAW,CAAC;mBACpD,aAAa;;;;WAIrB,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,QAAQ,GAAG;;eAE/B,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,aAAa,GAAG,GAAG,IAAI;CAC5D,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { ReactNode } from 'react';
2
+ type ToggleButtonProps<Value> = {
3
+ name: string;
4
+ value: Value;
5
+ onChange: (value: Value) => void;
6
+ isSelected: boolean;
7
+ isDisabled?: boolean;
8
+ children: ReactNode;
9
+ };
10
+ export declare const ToggleButton: <Value>({ name, value, onChange, isSelected, isDisabled, children, }: ToggleButtonProps<Value>) => JSX.Element;
11
+ export {};
@@ -0,0 +1,32 @@
1
+ import { Box } from '../Box';
2
+ import React from 'react';
3
+ import styled, { css } from 'styled-components';
4
+ export const ToggleButton = ({ name, value, onChange, isSelected, isDisabled = false, children, }) => {
5
+ return (React.createElement(Wrapper, { as: "label", "data-testId": `value-toggle-${value}`, isDisabled: isDisabled },
6
+ React.createElement(VisuallyHiddenInput, { type: "radio", name: name, checked: isSelected, onClick: () => onChange(value), onChange: () => onChange(value) }),
7
+ children));
8
+ };
9
+ const Wrapper = styled(Box) `
10
+ cursor: pointer;
11
+ ${({ isDisabled }) => isDisabled &&
12
+ css `
13
+ pointer-events: none;
14
+ opacity: 0.5;
15
+ `}
16
+ padding: 10px 14px;
17
+ transition: color 0.1s linear;
18
+ height: fit-content;
19
+ width: 100%;
20
+ align-content: center;
21
+ z-index: 3;
22
+ `;
23
+ const VisuallyHiddenInput = styled.input `
24
+ clip: rect(0 0 0 0);
25
+ clip-path: inset(50%);
26
+ height: 1px;
27
+ overflow: hidden;
28
+ position: absolute;
29
+ white-space: nowrap;
30
+ width: 1px;
31
+ `;
32
+ //# sourceMappingURL=ToggleButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToggleButton.js","sourceRoot":"","sources":["../../src/SegmentedControl/ToggleButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAW/C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAS,EACnC,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,UAAU,EACV,UAAU,GAAG,KAAK,EAClB,QAAQ,GACiB,EAAE,EAAE;IAC7B,OAAO,CACL,oBAAC,OAAO,IACN,EAAE,EAAC,OAAO,iBACG,gBAAgB,KAAK,EAAE,EACpC,UAAU,EAAE,UAAU;QAEtB,oBAAC,mBAAmB,IAClB,IAAI,EAAC,OAAO,EACZ,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC9B,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAC/B;QACD,QAAQ,CACD,CACX,CAAA;AACH,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAyB;;IAEhD,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnB,UAAU;IACV,GAAG,CAAA;;;KAGF;;;;;;;CAOJ,CAAA;AAED,MAAM,mBAAmB,GAAG,MAAM,CAAC,KAAK,CAAA;;;;;;;;CAQvC,CAAA"}
@@ -0,0 +1 @@
1
+ export * from './SegmentedControl';
@@ -0,0 +1,2 @@
1
+ export * from './SegmentedControl';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/SegmentedControl/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
package/dist/index.d.ts CHANGED
@@ -43,3 +43,4 @@ export * from './theme';
43
43
  export * from './utils/space';
44
44
  export * from './RichText';
45
45
  export * from './RichTextEditor';
46
+ export * from './SegmentedControl';
package/dist/index.js CHANGED
@@ -43,4 +43,5 @@ export * from './theme';
43
43
  export * from './utils/space';
44
44
  export * from './RichText';
45
45
  export * from './RichTextEditor';
46
+ export * from './SegmentedControl';
46
47
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AA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AAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,OAAO,CAAA;AACrB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA;AACrB,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrshmllw/smores-react",
3
- "version": "9.1.4",
3
+ "version": "9.2.0",
4
4
  "main": "./dist/index.js",
5
5
  "description": "Collection of React components used by Marshmallow Technology",
6
6
  "keywords": [