@searchspring/snap-preact-components 0.55.0 → 0.56.1
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/dist/cjs/components/Molecules/Grid/Grid.d.ts +20 -0
- package/dist/cjs/components/Molecules/Grid/Grid.d.ts.map +1 -0
- package/dist/cjs/components/Molecules/Grid/Grid.js +210 -0
- package/dist/cjs/components/Molecules/Grid/index.d.ts +2 -0
- package/dist/cjs/components/Molecules/Grid/index.d.ts.map +1 -0
- package/dist/cjs/components/Molecules/Grid/index.js +17 -0
- package/dist/cjs/components/Molecules/List/List.d.ts +18 -0
- package/dist/cjs/components/Molecules/List/List.d.ts.map +1 -0
- package/dist/cjs/components/Molecules/List/List.js +158 -0
- package/dist/cjs/components/Molecules/List/index.d.ts +2 -0
- package/dist/cjs/components/Molecules/List/index.d.ts.map +1 -0
- package/dist/cjs/components/Molecules/List/index.js +17 -0
- package/dist/cjs/components/Molecules/Swatches/Swatches.d.ts +19 -0
- package/dist/cjs/components/Molecules/Swatches/Swatches.d.ts.map +1 -0
- package/dist/cjs/components/Molecules/Swatches/Swatches.js +168 -0
- package/dist/cjs/components/Molecules/Swatches/index.d.ts +2 -0
- package/dist/cjs/components/Molecules/Swatches/index.d.ts.map +1 -0
- package/dist/cjs/components/Molecules/Swatches/index.js +17 -0
- package/dist/cjs/components/Molecules/VariantSelection/VariantSelection.d.ts +9 -0
- package/dist/cjs/components/Molecules/VariantSelection/VariantSelection.d.ts.map +1 -0
- package/dist/cjs/components/Molecules/VariantSelection/VariantSelection.js +146 -0
- package/dist/cjs/components/Molecules/VariantSelection/index.d.ts +2 -0
- package/dist/cjs/components/Molecules/VariantSelection/index.d.ts.map +1 -0
- package/dist/cjs/components/Molecules/VariantSelection/index.js +17 -0
- package/dist/cjs/index.d.ts +5 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/types.d.ts +15 -0
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/utilities/snapify.d.ts.map +1 -1
- package/dist/cjs/utilities/snapify.js +3 -0
- package/dist/esm/components/Molecules/Grid/Grid.d.ts +20 -0
- package/dist/esm/components/Molecules/Grid/Grid.d.ts.map +1 -0
- package/dist/esm/components/Molecules/Grid/Grid.js +189 -0
- package/dist/esm/components/Molecules/Grid/index.d.ts +2 -0
- package/dist/esm/components/Molecules/Grid/index.d.ts.map +1 -0
- package/dist/esm/components/Molecules/Grid/index.js +1 -0
- package/dist/esm/components/Molecules/List/List.d.ts +18 -0
- package/dist/esm/components/Molecules/List/List.d.ts.map +1 -0
- package/dist/esm/components/Molecules/List/List.js +140 -0
- package/dist/esm/components/Molecules/List/index.d.ts +2 -0
- package/dist/esm/components/Molecules/List/index.d.ts.map +1 -0
- package/dist/esm/components/Molecules/List/index.js +1 -0
- package/dist/esm/components/Molecules/Swatches/Swatches.d.ts +19 -0
- package/dist/esm/components/Molecules/Swatches/Swatches.d.ts.map +1 -0
- package/dist/esm/components/Molecules/Swatches/Swatches.js +179 -0
- package/dist/esm/components/Molecules/Swatches/index.d.ts +2 -0
- package/dist/esm/components/Molecules/Swatches/index.d.ts.map +1 -0
- package/dist/esm/components/Molecules/Swatches/index.js +1 -0
- package/dist/esm/components/Molecules/VariantSelection/VariantSelection.d.ts +9 -0
- package/dist/esm/components/Molecules/VariantSelection/VariantSelection.d.ts.map +1 -0
- package/dist/esm/components/Molecules/VariantSelection/VariantSelection.js +167 -0
- package/dist/esm/components/Molecules/VariantSelection/index.d.ts +2 -0
- package/dist/esm/components/Molecules/VariantSelection/index.d.ts.map +1 -0
- package/dist/esm/components/Molecules/VariantSelection/index.js +1 -0
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/types.d.ts +15 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/utilities/snapify.d.ts.map +1 -1
- package/dist/esm/utilities/snapify.js +3 -0
- package/package.json +12 -11
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { Fragment } from 'preact';
|
|
3
|
+
import { jsx, css } from '@emotion/react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { useTheme, CacheProvider } from '../../../providers';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
import { useA11y } from '../../../hooks';
|
|
8
|
+
import { Image } from '../../Atoms/Image';
|
|
9
|
+
import { cloneWithProps, defined } from '../../../utilities';
|
|
10
|
+
import { filters } from '@searchspring/snap-toolbox';
|
|
11
|
+
const CSS = {
|
|
12
|
+
Grid: ({ theme, columns, gapSize, disableOverflowAction }) => css({
|
|
13
|
+
'.ss__grid__options': {
|
|
14
|
+
display: 'flex',
|
|
15
|
+
flexFlow: 'row wrap',
|
|
16
|
+
gridTemplateColumns: `repeat(${columns}, 1fr)`,
|
|
17
|
+
gap: gapSize,
|
|
18
|
+
gridAutoRows: `1fr`,
|
|
19
|
+
'& .ss__grid__option': {
|
|
20
|
+
display: 'flex',
|
|
21
|
+
flexDirection: 'column',
|
|
22
|
+
boxSizing: 'content-box',
|
|
23
|
+
backgroundRepeat: 'no-repeat',
|
|
24
|
+
backgroundSize: `calc(100% / ${columns} - ${2 * Math.round((columns + 2) / 2)}px)`,
|
|
25
|
+
backgroundPosition: 'center !important',
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
flex: '0 1 auto',
|
|
29
|
+
border: `1px solid ${theme?.colors?.primary || '#333'}`,
|
|
30
|
+
textAlign: 'center',
|
|
31
|
+
wordBreak: 'break-all',
|
|
32
|
+
padding: '1em 0',
|
|
33
|
+
width: `calc(100% / ${columns} - ${2 * Math.round((columns + 2) / 2)}px)`,
|
|
34
|
+
margin: `0 ${gapSize} ${gapSize} 0`,
|
|
35
|
+
'.ss__grid__option__label': {
|
|
36
|
+
cursor: 'pointer',
|
|
37
|
+
},
|
|
38
|
+
[`:nth-of-type(${columns}n)`]: {
|
|
39
|
+
marginRight: '0',
|
|
40
|
+
},
|
|
41
|
+
'&.ss__grid__option--selected': {
|
|
42
|
+
border: `2px solid ${theme?.colors?.primary || '#333'}`,
|
|
43
|
+
},
|
|
44
|
+
'&.ss__grid__option--disabled': {
|
|
45
|
+
position: 'relative',
|
|
46
|
+
opacity: '.5',
|
|
47
|
+
cursor: 'none',
|
|
48
|
+
pointerEvents: 'none',
|
|
49
|
+
},
|
|
50
|
+
'&.ss__grid__option--unavailable': {
|
|
51
|
+
position: 'relative',
|
|
52
|
+
opacity: '.5',
|
|
53
|
+
},
|
|
54
|
+
'&.ss__grid__option--disabled:before, &.ss__grid__option--unavailable:before': {
|
|
55
|
+
content: '""',
|
|
56
|
+
display: 'block',
|
|
57
|
+
position: 'absolute',
|
|
58
|
+
top: '50%',
|
|
59
|
+
width: '90%',
|
|
60
|
+
height: '1px',
|
|
61
|
+
borderTop: '3px solid #eee',
|
|
62
|
+
outline: '1px solid #ffff',
|
|
63
|
+
transform: 'rotate(-45deg)',
|
|
64
|
+
},
|
|
65
|
+
'&:hover:not(.ss__grid__option--selected)': {
|
|
66
|
+
cursor: 'pointer',
|
|
67
|
+
background: theme?.colors?.hover || '#f8f8f8',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
'@supports (display: grid)': {
|
|
71
|
+
display: 'grid',
|
|
72
|
+
'& .ss__grid__option': {
|
|
73
|
+
padding: '0',
|
|
74
|
+
margin: '0',
|
|
75
|
+
width: 'initial',
|
|
76
|
+
},
|
|
77
|
+
'&::before': {
|
|
78
|
+
content: '""',
|
|
79
|
+
width: 0,
|
|
80
|
+
paddingBottom: '100%',
|
|
81
|
+
gridRow: '1 / 1',
|
|
82
|
+
gridColumn: '1 / 1',
|
|
83
|
+
},
|
|
84
|
+
'&> *:first-of-type': {
|
|
85
|
+
gridRow: '1 / 1',
|
|
86
|
+
gridColumn: '1 / 1',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
'.ss__grid__show-more-wrapper': {
|
|
91
|
+
'&:hover': {
|
|
92
|
+
cursor: disableOverflowAction ? 'initial !important' : 'pointer !important',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
export function Grid(properties) {
|
|
98
|
+
const globalTheme = useTheme();
|
|
99
|
+
const theme = { ...globalTheme, ...properties.theme };
|
|
100
|
+
const props = {
|
|
101
|
+
// default props
|
|
102
|
+
multiSelect: false,
|
|
103
|
+
columns: 4,
|
|
104
|
+
gapSize: '8px',
|
|
105
|
+
// global theme
|
|
106
|
+
...globalTheme?.components?.grid,
|
|
107
|
+
// props
|
|
108
|
+
...properties,
|
|
109
|
+
...properties.theme?.components?.grid,
|
|
110
|
+
};
|
|
111
|
+
const { titleText, onSelect, hideLabels, disableOverflowAction, multiSelect, overflowButton, columns, rows, hideShowLess, gapSize, overflowButtonInGrid, disabled, options, disableStyles, onOverflowButtonClick, className, style, } = props;
|
|
112
|
+
const subProps = {
|
|
113
|
+
image: {
|
|
114
|
+
// default props
|
|
115
|
+
className: 'ss__swatches__Image',
|
|
116
|
+
// global theme
|
|
117
|
+
...globalTheme?.components?.image,
|
|
118
|
+
// inherited props
|
|
119
|
+
...defined({
|
|
120
|
+
disableStyles,
|
|
121
|
+
}),
|
|
122
|
+
// component theme overrides
|
|
123
|
+
theme: props?.theme,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
let selected = props.selected;
|
|
127
|
+
const styling = {};
|
|
128
|
+
if (!disableStyles) {
|
|
129
|
+
styling.css = [CSS.Grid({ theme, columns, gapSize, disableOverflowAction }), style];
|
|
130
|
+
}
|
|
131
|
+
else if (style) {
|
|
132
|
+
styling.css = [style];
|
|
133
|
+
}
|
|
134
|
+
if (selected && !Array.isArray(selected)) {
|
|
135
|
+
selected = [selected];
|
|
136
|
+
}
|
|
137
|
+
// selection state
|
|
138
|
+
const [selection, setSelection] = useState(selected || []);
|
|
139
|
+
const makeSelection = (e, option) => {
|
|
140
|
+
if (multiSelect) {
|
|
141
|
+
let newArray;
|
|
142
|
+
if (selection.find((select) => select.value === option.value)) {
|
|
143
|
+
newArray = [...selection];
|
|
144
|
+
newArray.splice(newArray.findIndex((select) => select.value === option.value), 1);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
newArray = [...selection, option];
|
|
148
|
+
}
|
|
149
|
+
if (onSelect) {
|
|
150
|
+
onSelect(e, option, newArray);
|
|
151
|
+
}
|
|
152
|
+
setSelection(newArray);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
if (onSelect) {
|
|
156
|
+
onSelect(e, option, [option]);
|
|
157
|
+
}
|
|
158
|
+
setSelection([option]);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const limit = rows && columns ? columns * rows : options.length;
|
|
162
|
+
const remainder = Math.max(0, options.length - (limit - (overflowButtonInGrid ? 1 : 0)));
|
|
163
|
+
const [limited, setLimited] = useState(remainder);
|
|
164
|
+
const OverflowButtonElem = () => {
|
|
165
|
+
const showButton = hideShowLess ? (!limited ? false : true) : true;
|
|
166
|
+
return showButton && remainder > 0 && options.length !== limit ? (jsx("div", { className: `ss__grid__show-more-wrapper ${overflowButtonInGrid ? 'ss__grid__option' : ''}`, onClick: (e) => {
|
|
167
|
+
!disableOverflowAction && setLimited(!limited);
|
|
168
|
+
onOverflowButtonClick && onOverflowButtonClick(e, Boolean(limited), remainder);
|
|
169
|
+
} }, overflowButton ? (cloneWithProps(overflowButton, { limited, remainder })) : limited ? (jsx("span", { className: 'ss__grid__show-more' }, `+ ${remainder}`)) : remainder ? (jsx("span", { className: 'ss__grid__show-less' }, "Less")) : (jsx(Fragment, null)))) : (jsx(Fragment, null));
|
|
170
|
+
};
|
|
171
|
+
return typeof options == 'object' && options?.length ? (jsx(CacheProvider, null,
|
|
172
|
+
jsx("div", { ...styling, className: classnames('ss__grid', disabled ? 'ss__grid--disabled' : '', className) },
|
|
173
|
+
titleText && jsx("h5", { className: "ss__grid__title" }, titleText),
|
|
174
|
+
jsx("div", { className: "ss__grid__options" },
|
|
175
|
+
options.map((option, idx) => {
|
|
176
|
+
const selected = selection.some((select) => select.value == option.value);
|
|
177
|
+
if (!limited || options.length == limit || idx < limit - (overflowButtonInGrid ? 1 : 0)) {
|
|
178
|
+
return (jsx("div", { className: classnames(`ss__grid__option ss__grid__option--${filters.handleize(option.value.toString())}`, {
|
|
179
|
+
'ss__grid__option--selected': selected,
|
|
180
|
+
'ss__grid__option--disabled': option?.disabled,
|
|
181
|
+
'ss__grid__option--unavailable': option?.available === false,
|
|
182
|
+
}), style: { background: option.background ? option.background : option.backgroundImageUrl ? undefined : option.value }, onClick: (e) => !disabled && !option?.disabled && makeSelection(e, option), ref: (e) => useA11y(e), title: option.label, role: "option", "aria-selected": selected },
|
|
183
|
+
!option.background && option.backgroundImageUrl ? (jsx(Image, { ...subProps.image, src: option.backgroundImageUrl, alt: option.label || option.value.toString() })) : (jsx(Fragment, null)),
|
|
184
|
+
!hideLabels ? jsx("label", { className: "ss__grid__option__label" }, option.label || option.value) : jsx(Fragment, null)));
|
|
185
|
+
}
|
|
186
|
+
}),
|
|
187
|
+
overflowButtonInGrid ? jsx(OverflowButtonElem, null) : jsx(Fragment, null)),
|
|
188
|
+
!overflowButtonInGrid ? jsx(OverflowButtonElem, null) : jsx(Fragment, null)))) : (jsx(Fragment, null));
|
|
189
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Molecules/Grid/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Grid';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ComponentProps, ListOption } from '../../../types';
|
|
3
|
+
export declare function List(properties: ListProps): JSX.Element;
|
|
4
|
+
export interface ListProps extends ComponentProps {
|
|
5
|
+
options: ListOption[];
|
|
6
|
+
multiSelect?: boolean;
|
|
7
|
+
hideOptionCheckboxes?: boolean;
|
|
8
|
+
hideOptionLabels?: boolean;
|
|
9
|
+
hideOptionIcons?: boolean;
|
|
10
|
+
onSelect?: (e: React.MouseEvent<HTMLElement>, option: ListOption, selected: ListOption[]) => void;
|
|
11
|
+
titleText?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
horizontal?: boolean;
|
|
14
|
+
native?: boolean;
|
|
15
|
+
selected?: ListOption | ListOption[];
|
|
16
|
+
requireSelection?: boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=List.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../../../src/components/Molecules/List/List.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,cAAc,EAAc,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAyDxE,wBAAgB,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,GAAG,CAAC,OAAO,CA+IvD;AAED,MAAM,WAAW,SAAU,SAAQ,cAAc;IAChD,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;IAClG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,EAAE,CAAC;IACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { Fragment } from 'preact';
|
|
3
|
+
import { jsx, css } from '@emotion/react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { useTheme, CacheProvider } from '../../../providers';
|
|
6
|
+
import { defined } from '../../../utilities';
|
|
7
|
+
import { useState } from 'react';
|
|
8
|
+
import { Checkbox } from '../Checkbox';
|
|
9
|
+
import { useA11y } from '../../../hooks';
|
|
10
|
+
import { Icon } from '../../Atoms/Icon';
|
|
11
|
+
import { filters } from '@searchspring/snap-toolbox';
|
|
12
|
+
const CSS = {
|
|
13
|
+
List: ({ horizontal }) => css({
|
|
14
|
+
display: 'flex',
|
|
15
|
+
flexDirection: horizontal ? 'row' : 'column',
|
|
16
|
+
alignItems: horizontal ? 'center' : undefined,
|
|
17
|
+
justifyItems: 'flex-start',
|
|
18
|
+
gap: '5px',
|
|
19
|
+
'& .ss__list__options': {
|
|
20
|
+
border: 'none',
|
|
21
|
+
listStyle: 'none',
|
|
22
|
+
padding: '0px',
|
|
23
|
+
margin: '0px',
|
|
24
|
+
display: 'flex',
|
|
25
|
+
flexDirection: horizontal ? 'row' : 'column',
|
|
26
|
+
alignItems: horizontal ? 'center' : undefined,
|
|
27
|
+
justifyItems: 'flex-start',
|
|
28
|
+
gap: '5px',
|
|
29
|
+
},
|
|
30
|
+
'.ss__list__option': {
|
|
31
|
+
cursor: 'pointer',
|
|
32
|
+
display: 'flex',
|
|
33
|
+
alignItems: 'center',
|
|
34
|
+
gap: '5px',
|
|
35
|
+
'& .ss__list__option__label , .ss__list__option__icon': {
|
|
36
|
+
cursor: 'pointer',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
'&.ss__list--disabled, .ss__list__option--disabled': {
|
|
40
|
+
cursor: 'none',
|
|
41
|
+
pointerEvents: 'none',
|
|
42
|
+
opacity: 0.5,
|
|
43
|
+
},
|
|
44
|
+
'&.ss__list--disabled, .ss__list__option--unavailable': {
|
|
45
|
+
cursor: 'pointer',
|
|
46
|
+
opacity: 0.5,
|
|
47
|
+
},
|
|
48
|
+
'.ss__list__option--selected': {
|
|
49
|
+
fontWeight: 'bold',
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
export function List(properties) {
|
|
54
|
+
const globalTheme = useTheme();
|
|
55
|
+
const props = {
|
|
56
|
+
// default props
|
|
57
|
+
// global theme
|
|
58
|
+
...globalTheme?.components?.list,
|
|
59
|
+
// props
|
|
60
|
+
...properties,
|
|
61
|
+
...properties.theme?.components?.list,
|
|
62
|
+
};
|
|
63
|
+
const { titleText, onSelect, native, multiSelect, hideOptionLabels, hideOptionIcons, hideOptionCheckboxes, disabled, options, requireSelection, disableStyles, className, style, horizontal, } = props;
|
|
64
|
+
let selected = props.selected;
|
|
65
|
+
const subProps = {
|
|
66
|
+
checkbox: {
|
|
67
|
+
// default props
|
|
68
|
+
native: native,
|
|
69
|
+
// inherited props
|
|
70
|
+
...defined({
|
|
71
|
+
disableStyles,
|
|
72
|
+
}),
|
|
73
|
+
// component theme overrides
|
|
74
|
+
theme: props?.theme,
|
|
75
|
+
},
|
|
76
|
+
icon: {
|
|
77
|
+
// default props
|
|
78
|
+
className: 'ss__list__option__icon',
|
|
79
|
+
// inherited props
|
|
80
|
+
...defined({
|
|
81
|
+
disableStyles,
|
|
82
|
+
}),
|
|
83
|
+
// component theme overrides
|
|
84
|
+
theme: props?.theme,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
const styling = {};
|
|
88
|
+
if (!disableStyles) {
|
|
89
|
+
styling.css = [CSS.List({ horizontal }), style];
|
|
90
|
+
}
|
|
91
|
+
else if (style) {
|
|
92
|
+
styling.css = [style];
|
|
93
|
+
}
|
|
94
|
+
if (selected && !Array.isArray(selected)) {
|
|
95
|
+
selected = [selected];
|
|
96
|
+
}
|
|
97
|
+
// selection state
|
|
98
|
+
const [selection, setSelection] = useState(selected || []);
|
|
99
|
+
const makeSelection = (e, option) => {
|
|
100
|
+
let newArray;
|
|
101
|
+
if (multiSelect) {
|
|
102
|
+
if (selection.find((select) => select.value === option.value)) {
|
|
103
|
+
newArray = [...selection];
|
|
104
|
+
newArray.splice(newArray.findIndex((select) => select.value === option.value), 1);
|
|
105
|
+
if (newArray.length == 0 && requireSelection) {
|
|
106
|
+
newArray = [option];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
newArray = [...selection, option];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (!requireSelection && selection.find((select) => select.value === option.value)) {
|
|
115
|
+
newArray = [];
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
newArray = [option];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (onSelect) {
|
|
122
|
+
onSelect(e, option, newArray);
|
|
123
|
+
}
|
|
124
|
+
setSelection(newArray);
|
|
125
|
+
};
|
|
126
|
+
return typeof options == 'object' && options?.length ? (jsx(CacheProvider, null,
|
|
127
|
+
jsx("div", { ...styling, className: classnames('ss__list', disabled ? 'ss__list--disabled' : '', className) },
|
|
128
|
+
titleText && jsx("h5", { className: "ss__list__title" }, titleText),
|
|
129
|
+
jsx("ul", { className: `ss__list__options`, role: "listbox", "aria-label": titleText }, options.map((option) => {
|
|
130
|
+
const selected = selection.some((select) => select.value == option.value);
|
|
131
|
+
return (jsx("li", { className: classnames(`ss__list__option ss__list__option--${filters.handleize(option.value.toString())}`, {
|
|
132
|
+
'ss__list__option--selected': selected,
|
|
133
|
+
'ss__list__option--disabled': option?.disabled,
|
|
134
|
+
'ss__list__option--unavailable': option?.available === false,
|
|
135
|
+
}), ref: (e) => useA11y(e), onClick: (e) => !disabled && !option?.disabled && makeSelection(e, option), title: option.label, role: "option", "aria-selected": selected },
|
|
136
|
+
!hideOptionCheckboxes && jsx(Checkbox, { ...subProps.checkbox, checked: selected, disableA11y: true }),
|
|
137
|
+
option.icon && !hideOptionIcons && (jsx(Icon, { ...subProps.icon, ...(typeof option.icon == 'string' ? { icon: option.icon } : option.icon) })),
|
|
138
|
+
!hideOptionLabels && (option.label || !option.icon) && (jsx("label", { className: "ss__list__option__label" }, option.label || option.value))));
|
|
139
|
+
}))))) : (jsx(Fragment, null));
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Molecules/List/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './List';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ComponentProps, SwatchOption, BreakpointsProps } from '../../../types';
|
|
3
|
+
import { CarouselProps } from '../Carousel';
|
|
4
|
+
import { GridProps } from '../Grid';
|
|
5
|
+
export declare function Swatches(properties: SwatchesProps): JSX.Element;
|
|
6
|
+
export type SwatchesProps = {
|
|
7
|
+
options: SwatchOption[];
|
|
8
|
+
onSelect?: (e: React.MouseEvent<HTMLElement>, option: SwatchOption) => void;
|
|
9
|
+
selected?: SwatchOption;
|
|
10
|
+
hideLabels?: boolean;
|
|
11
|
+
breakpoints?: BreakpointsProps;
|
|
12
|
+
} & ({
|
|
13
|
+
type?: 'carousel';
|
|
14
|
+
carousel?: Partial<CarouselProps>;
|
|
15
|
+
} | {
|
|
16
|
+
type?: 'grid';
|
|
17
|
+
grid?: Partial<GridProps>;
|
|
18
|
+
}) & ComponentProps;
|
|
19
|
+
//# sourceMappingURL=Swatches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Swatches.d.ts","sourceRoot":"","sources":["../../../../../src/components/Molecules/Swatches/Swatches.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,cAAc,EAAc,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG5F,OAAO,EAAY,aAAa,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAQ,SAAS,EAAE,MAAM,SAAS,CAAC;AAoD1C,wBAAgB,QAAQ,CAAC,UAAU,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CA2K/D;AAED,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC5E,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAC/B,GAAG,CACD;IACA,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACjC,GACD;IACA,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;CACzB,CACH,GACA,cAAc,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { Fragment } from 'preact';
|
|
3
|
+
import { jsx, css } from '@emotion/react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { useTheme, CacheProvider } from '../../../providers';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
import { useA11y, useDisplaySettings } from '../../../hooks';
|
|
8
|
+
import { Carousel } from '../Carousel';
|
|
9
|
+
import { defined } from '../../../utilities';
|
|
10
|
+
import { Grid } from '../Grid';
|
|
11
|
+
import { Image } from '../../Atoms/Image';
|
|
12
|
+
import deepmerge from 'deepmerge';
|
|
13
|
+
import { filters } from '@searchspring/snap-toolbox';
|
|
14
|
+
const CSS = {
|
|
15
|
+
Swatches: ({ theme }) => css({
|
|
16
|
+
marginTop: '10px',
|
|
17
|
+
'.ss__swatches__carousel__swatch': {
|
|
18
|
+
boxSizing: 'content-box',
|
|
19
|
+
cursor: 'pointer',
|
|
20
|
+
backgroundRepeat: 'no-repeat',
|
|
21
|
+
display: 'flex',
|
|
22
|
+
justifyContent: 'center',
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
border: `1px solid ${theme?.colors?.primary || '#333'}`,
|
|
25
|
+
aspectRatio: '1/1',
|
|
26
|
+
margin: 'auto',
|
|
27
|
+
flexDirection: 'column',
|
|
28
|
+
'&.ss__swatches__carousel__swatch--selected': {
|
|
29
|
+
border: `2px solid ${theme?.colors?.primary || '#333'}`,
|
|
30
|
+
},
|
|
31
|
+
'&.ss__swatches__carousel__swatch--disabled:before, &.ss__swatches__carousel__swatch--unavailable:before': {
|
|
32
|
+
content: '""',
|
|
33
|
+
display: 'block',
|
|
34
|
+
position: 'absolute',
|
|
35
|
+
top: '50%',
|
|
36
|
+
width: '90%',
|
|
37
|
+
height: '1px',
|
|
38
|
+
borderTop: '3px solid #eee',
|
|
39
|
+
outline: '1px solid #ffff',
|
|
40
|
+
transform: 'rotate(-45deg)',
|
|
41
|
+
},
|
|
42
|
+
'&.ss__swatches__carousel__swatch--disabled': {
|
|
43
|
+
position: 'relative',
|
|
44
|
+
cursor: 'none',
|
|
45
|
+
pointerEvents: 'none',
|
|
46
|
+
opacity: 0.5,
|
|
47
|
+
},
|
|
48
|
+
'&.ss__swatches__carousel__swatch--unavailable': {
|
|
49
|
+
cursor: 'pointer',
|
|
50
|
+
opacity: 0.5,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
export function Swatches(properties) {
|
|
56
|
+
const globalTheme = useTheme();
|
|
57
|
+
const theme = { ...globalTheme, ...properties.theme };
|
|
58
|
+
const defaultCarouselBreakpoints = {
|
|
59
|
+
0: {
|
|
60
|
+
carousel: {
|
|
61
|
+
slidesPerView: 3,
|
|
62
|
+
slidesPerGroup: 3,
|
|
63
|
+
spaceBetween: 10,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
768: {
|
|
67
|
+
carousel: {
|
|
68
|
+
slidesPerView: 4,
|
|
69
|
+
slidesPerGroup: 4,
|
|
70
|
+
spaceBetween: 10,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
1200: {
|
|
74
|
+
carousel: {
|
|
75
|
+
slidesPerView: 5,
|
|
76
|
+
slidesPerGroup: 5,
|
|
77
|
+
spaceBetween: 10,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
let props = {
|
|
82
|
+
// default props
|
|
83
|
+
type: 'carousel',
|
|
84
|
+
hideLabels: true,
|
|
85
|
+
// global theme
|
|
86
|
+
...globalTheme?.components?.swatches,
|
|
87
|
+
// props
|
|
88
|
+
...properties,
|
|
89
|
+
...properties.theme?.components?.swatches,
|
|
90
|
+
};
|
|
91
|
+
const breakpoints = props.breakpoints || (props.type == 'carousel' ? defaultCarouselBreakpoints : {});
|
|
92
|
+
const displaySettings = useDisplaySettings(breakpoints);
|
|
93
|
+
if (displaySettings && Object.keys(displaySettings).length) {
|
|
94
|
+
const theme = deepmerge(props?.theme || {}, displaySettings?.theme || {}, { arrayMerge: (destinationArray, sourceArray) => sourceArray });
|
|
95
|
+
props = {
|
|
96
|
+
...props,
|
|
97
|
+
...displaySettings,
|
|
98
|
+
theme,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const { onSelect, disabled, options, hideLabels, disableStyles, className, style, type, carousel, grid } = props;
|
|
102
|
+
const subProps = {
|
|
103
|
+
carousel: {
|
|
104
|
+
// default props
|
|
105
|
+
className: 'ss__swatches__carousel',
|
|
106
|
+
loop: false,
|
|
107
|
+
...carousel,
|
|
108
|
+
// global theme
|
|
109
|
+
...globalTheme?.components?.carousel,
|
|
110
|
+
// inherited props
|
|
111
|
+
...defined({
|
|
112
|
+
breakpoints,
|
|
113
|
+
disableStyles,
|
|
114
|
+
}),
|
|
115
|
+
// component theme overrides
|
|
116
|
+
theme: props?.theme,
|
|
117
|
+
},
|
|
118
|
+
grid: {
|
|
119
|
+
// default props
|
|
120
|
+
className: 'ss__swatches__grid',
|
|
121
|
+
hideLabels: hideLabels,
|
|
122
|
+
overflowButtonInGrid: true,
|
|
123
|
+
disableOverflowAction: true,
|
|
124
|
+
rows: 1,
|
|
125
|
+
columns: 6,
|
|
126
|
+
...grid,
|
|
127
|
+
// global theme
|
|
128
|
+
...globalTheme?.components?.grid,
|
|
129
|
+
// inherited props
|
|
130
|
+
...defined({
|
|
131
|
+
disableStyles,
|
|
132
|
+
}),
|
|
133
|
+
// component theme overrides
|
|
134
|
+
theme: props?.theme,
|
|
135
|
+
},
|
|
136
|
+
image: {
|
|
137
|
+
// default props
|
|
138
|
+
className: 'ss__swatches__image',
|
|
139
|
+
// global theme
|
|
140
|
+
...globalTheme?.components?.image,
|
|
141
|
+
// inherited props
|
|
142
|
+
...defined({
|
|
143
|
+
disableStyles,
|
|
144
|
+
}),
|
|
145
|
+
// component theme overrides
|
|
146
|
+
theme: props?.theme,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
const selected = props.selected;
|
|
150
|
+
const styling = {};
|
|
151
|
+
if (!disableStyles) {
|
|
152
|
+
styling.css = [CSS.Swatches({ theme }), style];
|
|
153
|
+
}
|
|
154
|
+
else if (style) {
|
|
155
|
+
styling.css = [style];
|
|
156
|
+
}
|
|
157
|
+
// selection state
|
|
158
|
+
const [selection, setSelection] = useState(selected || undefined);
|
|
159
|
+
const makeSelection = (e, option) => {
|
|
160
|
+
if (onSelect) {
|
|
161
|
+
onSelect(e, option);
|
|
162
|
+
}
|
|
163
|
+
setSelection(option);
|
|
164
|
+
};
|
|
165
|
+
return typeof options == 'object' && options?.length ? (jsx(CacheProvider, null,
|
|
166
|
+
jsx("div", { ...styling, className: classnames('ss__swatches', className) }, type == 'carousel' ? (jsx(Carousel, { ...subProps.carousel }, options.map((option) => {
|
|
167
|
+
const label = option.label;
|
|
168
|
+
const selected = selection?.value == option.value;
|
|
169
|
+
return (jsx("div", { className: classnames(`ss__swatches__carousel__swatch ss__swatches__carousel__swatch--${filters.handleize(option.value.toString())}`, {
|
|
170
|
+
'ss__swatches__carousel__swatch--selected': selected,
|
|
171
|
+
'ss__swatches__carousel__swatch--disabled': option?.disabled,
|
|
172
|
+
'ss__swatches__carousel__swatch--unavailable': option?.available === false,
|
|
173
|
+
}), title: label, style: { background: option.background ? option.background : option.backgroundImageUrl ? `` : option.value }, onClick: (e) => !disabled && !option?.disabled && makeSelection(e, option), ref: (e) => useA11y(e), role: "option", "aria-selected": selected },
|
|
174
|
+
!option.background && option.backgroundImageUrl ? (jsx(Image, { ...subProps.image, src: option.backgroundImageUrl, alt: option.label || option.value.toString() })) : (jsx(Fragment, null)),
|
|
175
|
+
!hideLabels && jsx("span", { className: "ss__swatches__carousel__swatch__value" }, label || option.value)));
|
|
176
|
+
}))) : (jsx(Grid, { ...subProps.grid, options: options, onSelect: (e, option) => {
|
|
177
|
+
!disabled && makeSelection(e, option);
|
|
178
|
+
}, selected: selected }))))) : (jsx(Fragment, null));
|
|
179
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Molecules/Swatches/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Swatches';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ComponentProps } from '../../../types';
|
|
3
|
+
import type { VariantSelection as VariantSelectionType } from '@searchspring/snap-store-mobx';
|
|
4
|
+
export declare const VariantSelection: (properties: VariantSelectionProps) => JSX.Element;
|
|
5
|
+
export interface VariantSelectionProps extends ComponentProps {
|
|
6
|
+
selection: VariantSelectionType;
|
|
7
|
+
type?: 'dropdown' | 'swatches' | 'list';
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=VariantSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VariantSelection.d.ts","sourceRoot":"","sources":["../../../../../src/components/Molecules/VariantSelection/VariantSelection.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,cAAc,EAAc,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAqD9F,eAAO,MAAM,gBAAgB,eAAyB,qBAAqB,KAAG,WAkK5E,CAAC;AASH,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC5D,SAAS,EAAE,oBAAoB,CAAC;IAChC,IAAI,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;CACxC"}
|