@mailstep/design-system 0.6.75-beta.0 → 0.6.75-beta.2

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": "@mailstep/design-system",
3
- "version": "0.6.75-beta.0",
3
+ "version": "0.6.75-beta.2",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "main": "./ui/index.js",
@@ -25,16 +25,26 @@ var __rest = (this && this.__rest) || function (s, e) {
25
25
  return t;
26
26
  };
27
27
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
28
- import styled, { css } from '@xstyled/styled-components';
29
28
  import { FieldLabel } from '../Label';
30
29
  import { SpaceAroundWrap } from '../SpaceAround';
31
- var StyledSpaceAroundWrap = styled(SpaceAroundWrap)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (_a) {
32
- var $labelPosition = _a.$labelPosition;
33
- return ($labelPosition === 'left' ? 'display: flex; align-items: center; margin-top: 1rem' : '');
30
+ import styled, { css } from '@xstyled/styled-components';
31
+ var isHorizontal = function (position) { return position && ['left', 'right'].includes(position); };
32
+ var StyledSpaceAroundWrap = styled(SpaceAroundWrap)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: ", ";\n justify-content: ", ";\n ", "\n"], ["\n display: flex;\n flex-direction: ", ";\n justify-content: ", ";\n ", "\n"])), function (_a) {
33
+ var labelPosition = _a.labelPosition;
34
+ return labelPosition === 'left' ? 'row' : labelPosition === 'right' ? 'row-reverse' : 'column';
35
+ }, function (_a) {
36
+ var labelPosition = _a.labelPosition;
37
+ return (labelPosition === 'right' ? 'flex-end' : 'flex-start');
38
+ }, function (_a) {
39
+ var labelPosition = _a.labelPosition;
40
+ return (isHorizontal(labelPosition) ? 'margin-top: 1rem' : '');
34
41
  });
35
- var StyledFieldLabel = styled(FieldLabel)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (_a) {
42
+ var StyledFieldLabel = styled(FieldLabel)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n ", "\n ", "\n"], ["\n ", "\n ", "\n"])), function (_a) {
43
+ var labelPosition = _a.labelPosition;
44
+ return (isHorizontal(labelPosition) ? 'margin-bottom: 0;' : '');
45
+ }, function (_a) {
36
46
  var labelPosition = _a.labelPosition;
37
- return (labelPosition === 'left' ? 'margin-bottom: 0; margin-right: 1rem;' : '');
47
+ return labelPosition === 'left' ? 'margin-right: 1rem;' : labelPosition === 'right' ? 'margin-left: 1rem;' : '';
38
48
  });
39
49
  var disabledStyles = css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n opacity: 0.4;\n"], ["\n opacity: 0.4;\n"])));
40
50
  var StyledToggle = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n aspect-ratio: 1 / 1;\n width: 100%;\n height: 100%;\n border-radius: 7px;\n background-color: lightGray5;\n border: 3px solid;\n border-color: lightGray5;\n position: relative;\n transition: all 100ms ease-out;\n\n ", "\n\n input:checked + & {\n background-color: red1;\n border-color: red1;\n\n & > span {\n transform: translate(75%, -50%);\n background-color: white;\n }\n }\n"], ["\n aspect-ratio: 1 / 1;\n width: 100%;\n height: 100%;\n border-radius: 7px;\n background-color: lightGray5;\n border: 3px solid;\n border-color: lightGray5;\n position: relative;\n transition: all 100ms ease-out;\n\n ", "\n\n input:checked + & {\n background-color: red1;\n border-color: red1;\n\n & > span {\n transform: translate(75%, -50%);\n background-color: white;\n }\n }\n"])), function (props) { return (props.disabled ? disabledStyles : ''); });
@@ -46,7 +56,7 @@ var HiddenInput = styled.input(templateObject_6 || (templateObject_6 = __makeTem
46
56
  var Wrapper = styled.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n position: relative;\n border-radius: 8px;\n overflow: hidden;\n flex-shrink: 0;\n &[data-appearance='primary'] {\n width: 24px;\n height: 14px;\n ", " {\n height: 10px;\n }\n }\n &[data-appearance='grid'] {\n width: 28px;\n height: 16px;\n ", " {\n height: 12px;\n }\n }\n"], ["\n position: relative;\n border-radius: 8px;\n overflow: hidden;\n flex-shrink: 0;\n &[data-appearance='primary'] {\n width: 24px;\n height: 14px;\n ", " {\n height: 10px;\n }\n }\n &[data-appearance='grid'] {\n width: 28px;\n height: 16px;\n ", " {\n height: 12px;\n }\n }\n"])), StyledDot, StyledDot);
47
57
  var Toggle = function (_a) {
48
58
  var onChange = _a.onChange, label = _a.label, name = _a.name, checked = _a.checked, defaultChecked = _a.defaultChecked, _b = _a.spaceAround, spaceAround = _b === void 0 ? false : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, _d = _a.labelPosition, labelPosition = _d === void 0 ? 'default' : _d, _e = _a.variant, variant = _e === void 0 ? 'primary' : _e, _f = _a.spaceBetween, spaceBetween = _f === void 0 ? false : _f, readOnly = _a.readOnly, rest = __rest(_a, ["onChange", "label", "name", "checked", "defaultChecked", "spaceAround", "disabled", "labelPosition", "variant", "spaceBetween", "readOnly"]);
49
- return (_jsxs(StyledSpaceAroundWrap, { spaceBetween: spaceBetween, spaceAround: spaceAround, "$labelPosition": labelPosition, children: [label && (_jsx(StyledFieldLabel, { htmlFor: name, labelPosition: labelPosition, children: label })), _jsxs(Wrapper, { "data-appearance": variant, children: [_jsx(HiddenInput, { name: name, type: "checkbox", checked: checked, "$enabled": !disabled, defaultChecked: defaultChecked, onChange: !disabled ? onChange : undefined, disabled: disabled, "data-cy": "".concat(name, "Switch"), readOnly: readOnly }), _jsx(StyledToggle, __assign({ active: !!checked, disabled: disabled }, rest, { children: _jsx(StyledDot, {}) }))] })] }));
59
+ return (_jsxs(StyledSpaceAroundWrap, { spaceBetween: spaceBetween, spaceAround: spaceAround, labelPosition: labelPosition, children: [label && (_jsx(StyledFieldLabel, { htmlFor: name, labelPosition: labelPosition, children: label })), _jsxs(Wrapper, { "data-appearance": variant, children: [_jsx(HiddenInput, { id: name, name: name, type: "checkbox", checked: checked, "$enabled": !disabled, defaultChecked: defaultChecked, onChange: !disabled ? onChange : undefined, disabled: disabled, "data-cy": "".concat(name, "Switch"), readOnly: readOnly }), _jsx(StyledToggle, __assign({ active: !!checked, disabled: disabled }, rest, { children: _jsx(StyledDot, {}) }))] })] }));
50
60
  };
51
61
  export default Toggle;
52
62
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
@@ -11,4 +11,6 @@ type Story = StoryObj<typeof meta>;
11
11
  export declare const Default: Story;
12
12
  export declare const Checked: Story;
13
13
  export declare const Disabled: Story;
14
+ export declare const LabelRight: Story;
15
+ export declare const LabelLeft: Story;
14
16
  export declare const VariantGrid: Story;
@@ -8,24 +8,46 @@ var meta = {
8
8
  export default meta;
9
9
  export var Default = {
10
10
  args: {
11
+ name: 'name',
11
12
  label: 'Label',
13
+ onChange: console.log
12
14
  },
13
15
  };
14
16
  export var Checked = {
15
17
  args: {
18
+ name: 'name',
16
19
  label: 'Label',
17
20
  checked: true,
21
+ onChange: console.log
18
22
  },
19
23
  };
20
24
  export var Disabled = {
21
25
  args: {
26
+ name: 'name',
22
27
  label: 'Label',
23
28
  checked: true,
24
29
  disabled: true,
25
30
  },
26
31
  };
32
+ export var LabelRight = {
33
+ args: {
34
+ name: 'name',
35
+ label: 'Label',
36
+ checked: true,
37
+ labelPosition: 'right'
38
+ },
39
+ };
40
+ export var LabelLeft = {
41
+ args: {
42
+ name: 'name',
43
+ label: 'Label',
44
+ checked: true,
45
+ labelPosition: 'left'
46
+ },
47
+ };
27
48
  export var VariantGrid = {
28
49
  args: {
50
+ name: 'name',
29
51
  label: 'Label',
30
52
  checked: true,
31
53
  variant: 'grid',
@@ -6,6 +6,8 @@ type SpaceAroundProps = {
6
6
  marginLeft?: number;
7
7
  };
8
8
  type SpaceAround = boolean | SpaceAroundProps;
9
+ export type LabelPosition = 'default' | 'left' | 'right';
10
+ export type Variant = 'primary' | 'grid';
9
11
  export type Props = {
10
12
  onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
11
13
  label?: string;
@@ -15,8 +17,8 @@ export type Props = {
15
17
  spaceAround?: SpaceAround;
16
18
  spaceBetween?: boolean;
17
19
  disabled?: boolean;
18
- labelPosition?: 'default' | 'left';
19
- variant?: 'primary' | 'grid';
20
+ labelPosition?: LabelPosition;
21
+ variant?: Variant;
20
22
  readOnly?: boolean;
21
23
  };
22
24
  export {};