@telus-uds/components-base 3.31.0 → 3.32.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.
- package/CHANGELOG.md +17 -1
- package/lib/cjs/Button/ButtonGroup.js +91 -23
- package/lib/cjs/Card/CardBase.js +75 -47
- package/lib/cjs/ColourToggle/ColourBubble.js +65 -12
- package/lib/cjs/ColourToggle/ColourToggle.js +40 -11
- package/lib/cjs/ColourToggle/constants.js +15 -0
- package/lib/cjs/ColourToggle/dictionary.js +15 -0
- package/lib/cjs/Validator/Validator.js +5 -1
- package/lib/esm/Button/ButtonGroup.js +91 -23
- package/lib/esm/Card/CardBase.js +75 -47
- package/lib/esm/ColourToggle/ColourBubble.js +66 -13
- package/lib/esm/ColourToggle/ColourToggle.js +41 -12
- package/lib/esm/ColourToggle/constants.js +8 -0
- package/lib/esm/ColourToggle/dictionary.js +9 -0
- package/lib/esm/Validator/Validator.js +5 -1
- package/lib/package.json +2 -2
- package/package.json +2 -2
- package/src/Button/ButtonGroup.jsx +93 -24
- package/src/Card/CardBase.jsx +94 -75
- package/src/ColourToggle/ColourBubble.jsx +62 -7
- package/src/ColourToggle/ColourToggle.jsx +50 -10
- package/src/ColourToggle/constants.js +10 -0
- package/src/ColourToggle/dictionary.js +6 -0
- package/src/Validator/Validator.jsx +5 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UNAVAILABLE_VARIANT = exports.DICTIONARY_CONTENT_SHAPE = void 0;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const UNAVAILABLE_VARIANT = exports.UNAVAILABLE_VARIANT = {
|
|
10
|
+
DARK: 'dark',
|
|
11
|
+
LIGHT: 'light'
|
|
12
|
+
};
|
|
13
|
+
const DICTIONARY_CONTENT_SHAPE = exports.DICTIONARY_CONTENT_SHAPE = _propTypes.default.shape({
|
|
14
|
+
unavailable: _propTypes.default.string
|
|
15
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const DEFAULT_COLOUR_TOGGLE_DICTIONARY = {
|
|
8
|
+
en: {
|
|
9
|
+
unavailable: '(Out of stock)'
|
|
10
|
+
},
|
|
11
|
+
fr: {
|
|
12
|
+
unavailable: '(En rupture de stock)'
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var _default = exports.default = DEFAULT_COLOUR_TOGGLE_DICTIONARY;
|
|
@@ -206,7 +206,11 @@ const Validator = /*#__PURE__*/_react.default.forwardRef((_ref2, ref) => {
|
|
|
206
206
|
|
|
207
207
|
// Sync external value prop to internal state
|
|
208
208
|
_react.default.useEffect(() => {
|
|
209
|
-
if (value
|
|
209
|
+
if (value === '') {
|
|
210
|
+
setCodes(Array(validatorsLength).fill(''));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (Number(value).toString() !== 'NaN') {
|
|
210
214
|
const digits = value.split('').slice(0, validatorsLength);
|
|
211
215
|
const newCodes = Array(validatorsLength).fill('');
|
|
212
216
|
digits.forEach((digit, i) => {
|
|
@@ -13,6 +13,8 @@ import { getPressHandlersWithArgs } from '../utils/pressability';
|
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
15
15
|
const [selectItemProps, selectedItemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, pressProps, viewProps]);
|
|
16
|
+
const EQUAL_WIDTH = 'equal';
|
|
17
|
+
const RESPONSIVE_WIDTH = 'responsive';
|
|
16
18
|
const ButtonGroup = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
17
19
|
let {
|
|
18
20
|
variant,
|
|
@@ -57,31 +59,90 @@ const ButtonGroup = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
57
59
|
const isMobileNonContained = Platform.OS !== 'web' && (!variant || variant?.style !== 'contained');
|
|
58
60
|
const themeButtonTokensCallback = useThemeTokensCallback('ButtonGroupItem', tokens, variant);
|
|
59
61
|
const gapValue = useSpacingScale(gap || space);
|
|
62
|
+
const isWeb = Platform.OS === 'web';
|
|
63
|
+
const buttonWidthVariant = variant?.width;
|
|
60
64
|
const getButtonTokens = useCallback(state => {
|
|
61
65
|
const themeButtonTokens = themeButtonTokensCallback(state);
|
|
62
66
|
const shouldUseTransparentBackground = isMobileNonContained && !state.selected && !state.pressed && !state.hover && !state.focus;
|
|
67
|
+
let widthStyle;
|
|
68
|
+
switch (buttonWidthVariant) {
|
|
69
|
+
case EQUAL_WIDTH:
|
|
70
|
+
widthStyle = staticStyles.equalWidth;
|
|
71
|
+
break;
|
|
72
|
+
case RESPONSIVE_WIDTH:
|
|
73
|
+
widthStyle = staticStyles.responsiveWidth;
|
|
74
|
+
break;
|
|
75
|
+
// no default
|
|
76
|
+
}
|
|
63
77
|
return {
|
|
64
78
|
...themeButtonTokens,
|
|
65
|
-
...
|
|
79
|
+
...widthStyle,
|
|
66
80
|
...(shouldUseTransparentBackground && {
|
|
67
81
|
backgroundColor: 'transparent'
|
|
68
82
|
}),
|
|
69
83
|
alignSelf: themeButtonTokens.width ? 'flex-start' : 'center'
|
|
70
84
|
};
|
|
71
|
-
}, [themeButtonTokensCallback, isMobileNonContained,
|
|
72
|
-
const fieldsetStyles = useMemo(() =>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
}, [themeButtonTokensCallback, isMobileNonContained, buttonWidthVariant]);
|
|
86
|
+
const fieldsetStyles = useMemo(() => {
|
|
87
|
+
let fieldSetBase;
|
|
88
|
+
switch (buttonWidthVariant) {
|
|
89
|
+
case EQUAL_WIDTH:
|
|
90
|
+
case RESPONSIVE_WIDTH:
|
|
91
|
+
fieldSetBase = staticStyles.fieldSetResponsive;
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
fieldSetBase = staticStyles.fieldsetBase;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
...fieldSetBase,
|
|
99
|
+
borderRadius,
|
|
100
|
+
backgroundColor: isMobileNonContained ? 'transparent' : backgroundColor || 'transparent',
|
|
101
|
+
padding
|
|
102
|
+
};
|
|
103
|
+
}, [borderRadius, backgroundColor, padding, isMobileNonContained, buttonWidthVariant]);
|
|
104
|
+
const buttonsContainerStyles = useMemo(() => {
|
|
105
|
+
let flexWrap;
|
|
106
|
+
if (isWeb) {
|
|
107
|
+
flexWrap = 'wrap';
|
|
108
|
+
} else {
|
|
109
|
+
switch (buttonWidthVariant) {
|
|
110
|
+
case EQUAL_WIDTH:
|
|
111
|
+
case RESPONSIVE_WIDTH:
|
|
112
|
+
flexWrap = 'nowrap';
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
flexWrap = 'wrap';
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
let justifyContent;
|
|
120
|
+
switch (buttonWidthVariant) {
|
|
121
|
+
case EQUAL_WIDTH:
|
|
122
|
+
justifyContent = 'space-evenly';
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
justifyContent = 'flex-start';
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
let viewBaseStyle;
|
|
129
|
+
switch (buttonWidthVariant) {
|
|
130
|
+
case EQUAL_WIDTH:
|
|
131
|
+
case RESPONSIVE_WIDTH:
|
|
132
|
+
viewBaseStyle = {};
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
viewBaseStyle = staticStyles.viewBase;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
...viewBaseStyle,
|
|
140
|
+
flexWrap,
|
|
141
|
+
flexDirection: direction === 'column' ? 'column' : 'row',
|
|
142
|
+
gap: gapValue || 0,
|
|
143
|
+
justifyContent
|
|
144
|
+
};
|
|
145
|
+
}, [direction, gapValue, buttonWidthVariant, isWeb]);
|
|
85
146
|
const {
|
|
86
147
|
currentValues,
|
|
87
148
|
toggleOneValue
|
|
@@ -103,7 +164,7 @@ const ButtonGroup = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
103
164
|
}
|
|
104
165
|
|
|
105
166
|
// Some web screenreaders e.g. MacOS Voiceover don't handle radiogroups properly unless radio is direct child of radiogroup
|
|
106
|
-
const
|
|
167
|
+
const buttonsWrapperRole = Platform.OS === 'web' && accessibilityRole === 'radiogroup' ? accessibilityRole : undefined;
|
|
107
168
|
return /*#__PURE__*/_jsx(Fieldset, {
|
|
108
169
|
...systemProps,
|
|
109
170
|
ref: ref,
|
|
@@ -121,8 +182,8 @@ const ButtonGroup = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
121
182
|
style: fieldsetStyles,
|
|
122
183
|
...selectProps(rest),
|
|
123
184
|
children: /*#__PURE__*/_jsx(View, {
|
|
124
|
-
accessibilityRole:
|
|
125
|
-
style:
|
|
185
|
+
accessibilityRole: buttonsWrapperRole,
|
|
186
|
+
style: buttonsContainerStyles,
|
|
126
187
|
children: items.map((_ref2, index) => {
|
|
127
188
|
let {
|
|
128
189
|
label,
|
|
@@ -290,17 +351,24 @@ ButtonGroup.propTypes = {
|
|
|
290
351
|
copy: PropTypes.oneOf(['en', 'fr'])
|
|
291
352
|
};
|
|
292
353
|
const staticStyles = StyleSheet.create({
|
|
354
|
+
equalWidth: {
|
|
355
|
+
width: '100%',
|
|
356
|
+
flex: 1
|
|
357
|
+
},
|
|
358
|
+
responsiveWidth: {
|
|
359
|
+
width: 'auto'
|
|
360
|
+
},
|
|
293
361
|
fieldsetBase: {
|
|
294
362
|
alignSelf: 'flex-start',
|
|
295
|
-
display: 'inline'
|
|
363
|
+
display: 'inline',
|
|
364
|
+
width: 'auto'
|
|
365
|
+
},
|
|
366
|
+
fieldSetResponsive: {
|
|
367
|
+
width: '100%'
|
|
296
368
|
},
|
|
297
369
|
viewBase: {
|
|
298
370
|
flexWrap: 'wrap',
|
|
299
371
|
alignItems: 'center'
|
|
300
|
-
},
|
|
301
|
-
equalWidth: {
|
|
302
|
-
width: '100%',
|
|
303
|
-
flex: 1
|
|
304
372
|
}
|
|
305
373
|
});
|
|
306
374
|
export default ButtonGroup;
|
package/lib/esm/Card/CardBase.js
CHANGED
|
@@ -15,9 +15,7 @@ import FlexGridCol from '../FlexGrid/Col';
|
|
|
15
15
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
16
|
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
17
17
|
const GRID_COLUMNS = 12;
|
|
18
|
-
const isOverlayColor = color =>
|
|
19
|
-
return color && typeof color === 'string' && color.startsWith('rgba(');
|
|
20
|
-
};
|
|
18
|
+
const isOverlayColor = color => color && typeof color === 'string' && color.startsWith('rgba(');
|
|
21
19
|
const setBackgroundImage = _ref => {
|
|
22
20
|
let {
|
|
23
21
|
src,
|
|
@@ -26,7 +24,8 @@ const setBackgroundImage = _ref => {
|
|
|
26
24
|
backgroundImagePosition,
|
|
27
25
|
backgroundImageAlign,
|
|
28
26
|
content,
|
|
29
|
-
cardStyle
|
|
27
|
+
cardStyle,
|
|
28
|
+
testID
|
|
30
29
|
} = _ref;
|
|
31
30
|
const borderRadius = cardStyle?.borderRadius || 0;
|
|
32
31
|
const borderWidth = cardStyle?.borderWidth || 0;
|
|
@@ -86,6 +85,7 @@ const setBackgroundImage = _ref => {
|
|
|
86
85
|
style: [staticStyles.imageBackground, backgroundImageStyle],
|
|
87
86
|
role: "img",
|
|
88
87
|
"aria-label": alt,
|
|
88
|
+
testID: testID,
|
|
89
89
|
children: content
|
|
90
90
|
});
|
|
91
91
|
}
|
|
@@ -100,7 +100,8 @@ const setBackgroundImage = _ref => {
|
|
|
100
100
|
style: [staticStyles.containImage, positionStyles],
|
|
101
101
|
accessible: true,
|
|
102
102
|
accessibilityLabel: alt,
|
|
103
|
-
accessibilityIgnoresInvertColors: true
|
|
103
|
+
accessibilityIgnoresInvertColors: true,
|
|
104
|
+
testID: testID
|
|
104
105
|
}), /*#__PURE__*/_jsx(View, {
|
|
105
106
|
style: staticStyles.contentOverlay,
|
|
106
107
|
children: content
|
|
@@ -116,6 +117,7 @@ const setBackgroundImage = _ref => {
|
|
|
116
117
|
style: staticStyles.imageBackground,
|
|
117
118
|
accessible: true,
|
|
118
119
|
accessibilityLabel: alt,
|
|
120
|
+
testID: testID,
|
|
119
121
|
children: content
|
|
120
122
|
});
|
|
121
123
|
};
|
|
@@ -124,22 +126,13 @@ const selectPaddedContentStyles = _ref2 => {
|
|
|
124
126
|
paddingTop,
|
|
125
127
|
paddingBottom,
|
|
126
128
|
paddingLeft,
|
|
127
|
-
paddingRight
|
|
128
|
-
borderWidth,
|
|
129
|
-
borderColor,
|
|
130
|
-
borderRadius,
|
|
131
|
-
hasInteractiveBorder
|
|
129
|
+
paddingRight
|
|
132
130
|
} = _ref2;
|
|
133
131
|
return {
|
|
134
132
|
paddingTop,
|
|
135
133
|
paddingBottom,
|
|
136
134
|
paddingLeft,
|
|
137
|
-
paddingRight
|
|
138
|
-
...(hasInteractiveBorder ? {
|
|
139
|
-
borderWidth,
|
|
140
|
-
borderColor,
|
|
141
|
-
borderRadius
|
|
142
|
-
} : {})
|
|
135
|
+
paddingRight
|
|
143
136
|
};
|
|
144
137
|
};
|
|
145
138
|
const selectInteractiveOverlayStyles = _ref3 => {
|
|
@@ -158,12 +151,31 @@ const selectInteractiveOverlayStyles = _ref3 => {
|
|
|
158
151
|
backgroundColor,
|
|
159
152
|
borderRadius: adjustedBorderRadius,
|
|
160
153
|
pointerEvents: 'none',
|
|
161
|
-
zIndex:
|
|
154
|
+
zIndex: 3
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const selectOuterContainerStyles = _ref4 => {
|
|
158
|
+
let {
|
|
159
|
+
containerStyle,
|
|
160
|
+
backgroundColor,
|
|
161
|
+
borderRadius,
|
|
162
|
+
borderColor,
|
|
163
|
+
borderWidth,
|
|
164
|
+
hasGradientToken
|
|
165
|
+
} = _ref4;
|
|
166
|
+
return {
|
|
167
|
+
...containerStyle,
|
|
168
|
+
backgroundColor,
|
|
169
|
+
borderRadius,
|
|
170
|
+
...(hasGradientToken ? {} : {
|
|
171
|
+
borderColor,
|
|
172
|
+
borderWidth
|
|
173
|
+
})
|
|
162
174
|
};
|
|
163
175
|
};
|
|
164
176
|
|
|
165
177
|
// Ensure explicit selection of tokens
|
|
166
|
-
export const selectStyles =
|
|
178
|
+
export const selectStyles = function (_ref5) {
|
|
167
179
|
let {
|
|
168
180
|
flex,
|
|
169
181
|
backgroundColor,
|
|
@@ -184,7 +196,10 @@ export const selectStyles = _ref4 => {
|
|
|
184
196
|
gradient,
|
|
185
197
|
maxHeight,
|
|
186
198
|
overflowY
|
|
187
|
-
} =
|
|
199
|
+
} = _ref5;
|
|
200
|
+
let {
|
|
201
|
+
hasBgImage = false
|
|
202
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
188
203
|
const hasGradient = (gradient || backgroundGradient) && Platform.OS === 'web';
|
|
189
204
|
let backgroundImageValue = null;
|
|
190
205
|
if (hasGradient) {
|
|
@@ -213,7 +228,11 @@ export const selectStyles = _ref4 => {
|
|
|
213
228
|
...(gradient && Platform.OS === 'web' ? {
|
|
214
229
|
backgroundImage: backgroundImageValue,
|
|
215
230
|
backgroundOrigin: `border-box`,
|
|
216
|
-
|
|
231
|
+
// bgImage child fills the content-box and replaces what the inset shadow
|
|
232
|
+
// used to cover, so we omit it to avoid hiding the image.
|
|
233
|
+
...(hasBgImage ? {} : {
|
|
234
|
+
boxShadow: `inset 0 1000px ${boxShadowColor}`
|
|
235
|
+
}),
|
|
217
236
|
border: `${borderWidth}px solid transparent`
|
|
218
237
|
} : {}),
|
|
219
238
|
...(backgroundGradient && Platform.OS === 'web' ? {
|
|
@@ -230,7 +249,7 @@ export const selectStyles = _ref4 => {
|
|
|
230
249
|
* A themeless base component for Card which components can apply theme tokens to. Not
|
|
231
250
|
* intended to be used in apps or sites directly: build themed components on top of this.
|
|
232
251
|
*/
|
|
233
|
-
const CardBase = /*#__PURE__*/React.forwardRef((
|
|
252
|
+
const CardBase = /*#__PURE__*/React.forwardRef((_ref6, ref) => {
|
|
234
253
|
let {
|
|
235
254
|
children,
|
|
236
255
|
tokens,
|
|
@@ -238,15 +257,14 @@ const CardBase = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
238
257
|
backgroundImage,
|
|
239
258
|
fullBleedContent,
|
|
240
259
|
cardState,
|
|
260
|
+
testID,
|
|
241
261
|
...rest
|
|
242
|
-
} =
|
|
262
|
+
} = _ref6;
|
|
243
263
|
const resolvedTokens = typeof tokens === 'function' ? tokens(cardState) : tokens;
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
} : resolvedTokens;
|
|
249
|
-
const cardStyle = selectStyles(tokensToUse);
|
|
264
|
+
const hasBgImage = Boolean(backgroundImage && backgroundImage.src);
|
|
265
|
+
const cardStyle = selectStyles(resolvedTokens, {
|
|
266
|
+
hasBgImage
|
|
267
|
+
});
|
|
250
268
|
const props = selectProps(rest);
|
|
251
269
|
let content = children;
|
|
252
270
|
const {
|
|
@@ -279,31 +297,29 @@ const CardBase = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
279
297
|
...containerStyle
|
|
280
298
|
} = cardStyle;
|
|
281
299
|
const hasPadding = paddingTop || paddingBottom || paddingLeft || paddingRight;
|
|
282
|
-
const hasInteractiveBorder = borderWidth && borderWidth > 0;
|
|
283
300
|
const hasInteractiveOverlay = isOverlayColor(backgroundColor);
|
|
284
|
-
const
|
|
301
|
+
const outerBackgroundColor = hasInteractiveOverlay ? undefined : backgroundColor;
|
|
302
|
+
const hasGradientToken = Boolean(resolvedTokens.gradient) && Platform.OS === 'web';
|
|
303
|
+
const paddedContent = hasPadding ? /*#__PURE__*/_jsx(View, {
|
|
285
304
|
style: selectPaddedContentStyles({
|
|
286
305
|
paddingTop,
|
|
287
306
|
paddingBottom,
|
|
288
307
|
paddingLeft,
|
|
289
|
-
paddingRight
|
|
290
|
-
borderWidth,
|
|
291
|
-
borderColor,
|
|
292
|
-
borderRadius,
|
|
293
|
-
hasInteractiveBorder
|
|
308
|
+
paddingRight
|
|
294
309
|
}),
|
|
295
310
|
children: children
|
|
296
311
|
}) : children;
|
|
297
312
|
const contentWithOverlay = /*#__PURE__*/_jsxs(_Fragment, {
|
|
298
|
-
children: [
|
|
313
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
314
|
+
style: staticStyles.contentOverlay,
|
|
315
|
+
children: paddedContent
|
|
316
|
+
}), hasInteractiveOverlay && Platform.OS === 'web' && /*#__PURE__*/_jsx(View, {
|
|
299
317
|
style: selectInteractiveOverlayStyles({
|
|
300
318
|
backgroundColor,
|
|
301
319
|
borderRadius,
|
|
302
320
|
borderWidth
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
style: staticStyles.contentOverlay,
|
|
306
|
-
children: paddedContent
|
|
321
|
+
}),
|
|
322
|
+
testID: testID && `${testID}-card-base-bg-overlay`
|
|
307
323
|
})]
|
|
308
324
|
});
|
|
309
325
|
content = setBackgroundImage({
|
|
@@ -314,17 +330,23 @@ const CardBase = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
314
330
|
backgroundImageAlign,
|
|
315
331
|
content: contentWithOverlay,
|
|
316
332
|
cardStyle: {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
333
|
+
borderRadius,
|
|
334
|
+
borderWidth
|
|
335
|
+
},
|
|
336
|
+
testID: testID && `${testID}-card-base-bg-image`
|
|
320
337
|
});
|
|
321
338
|
return /*#__PURE__*/_jsx(View, {
|
|
322
|
-
style: {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
339
|
+
style: selectOuterContainerStyles({
|
|
340
|
+
containerStyle,
|
|
341
|
+
backgroundColor: outerBackgroundColor,
|
|
342
|
+
borderRadius,
|
|
343
|
+
borderColor,
|
|
344
|
+
borderWidth,
|
|
345
|
+
hasGradientToken
|
|
346
|
+
}),
|
|
326
347
|
dataSet: dataSet,
|
|
327
348
|
ref: ref,
|
|
349
|
+
testID: testID,
|
|
328
350
|
...props,
|
|
329
351
|
children: content
|
|
330
352
|
});
|
|
@@ -364,6 +386,7 @@ const CardBase = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
364
386
|
style: containerStyle,
|
|
365
387
|
dataSet: dataSet,
|
|
366
388
|
ref: ref,
|
|
389
|
+
testID: testID,
|
|
367
390
|
...props,
|
|
368
391
|
children: /*#__PURE__*/_jsx(FlexGrid, {
|
|
369
392
|
children: /*#__PURE__*/_jsx(FlexGridRow, {
|
|
@@ -380,6 +403,7 @@ const CardBase = /*#__PURE__*/React.forwardRef((_ref5, ref) => {
|
|
|
380
403
|
style: cardStyle,
|
|
381
404
|
dataSet: dataSet,
|
|
382
405
|
ref: ref,
|
|
406
|
+
testID: testID,
|
|
383
407
|
...props,
|
|
384
408
|
children: content
|
|
385
409
|
});
|
|
@@ -422,6 +446,10 @@ CardBase.propTypes = {
|
|
|
422
446
|
...selectedSystemPropTypes,
|
|
423
447
|
children: PropTypes.node,
|
|
424
448
|
tokens: getTokensPropType('Card'),
|
|
449
|
+
/**
|
|
450
|
+
* Identifier for testing purposes.
|
|
451
|
+
*/
|
|
452
|
+
testID: PropTypes.string,
|
|
425
453
|
/**
|
|
426
454
|
* Apply background image to the card.
|
|
427
455
|
*/
|
|
@@ -3,11 +3,13 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import View from "react-native-web/dist/exports/View";
|
|
4
4
|
import Pressable from "react-native-web/dist/exports/Pressable";
|
|
5
5
|
import Platform from "react-native-web/dist/exports/Platform";
|
|
6
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
6
7
|
import { resolvePressableTokens } from '../utils/pressability';
|
|
7
8
|
import { applyShadowToken } from '../ThemeProvider';
|
|
8
9
|
import { getTokensPropType } from '../utils';
|
|
9
10
|
import Tooltip from '../Tooltip';
|
|
10
|
-
import {
|
|
11
|
+
import { UNAVAILABLE_VARIANT } from './constants';
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
13
|
const selectGeneralBubbleTokens = _ref => {
|
|
12
14
|
let {
|
|
13
15
|
outerBubbleHeight,
|
|
@@ -63,37 +65,70 @@ const selectBorderBubbleTokens = _ref3 => {
|
|
|
63
65
|
borderRadius: bubbleBorderRadius
|
|
64
66
|
};
|
|
65
67
|
};
|
|
66
|
-
const
|
|
68
|
+
const selectOverlayStyles = _ref4 => {
|
|
67
69
|
let {
|
|
68
|
-
|
|
70
|
+
overlayColor,
|
|
71
|
+
innerBubbleBorderRadius
|
|
72
|
+
} = _ref4;
|
|
73
|
+
return {
|
|
74
|
+
borderRadius: innerBubbleBorderRadius,
|
|
75
|
+
backgroundColor: overlayColor
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const selectSlashStyles = (_ref5, unavailable) => {
|
|
79
|
+
let {
|
|
80
|
+
slashLightColor,
|
|
81
|
+
slashDarkColor,
|
|
82
|
+
slashWidth,
|
|
83
|
+
slashOffset
|
|
84
|
+
} = _ref5;
|
|
85
|
+
return {
|
|
86
|
+
width: slashWidth,
|
|
87
|
+
backgroundColor: unavailable === UNAVAILABLE_VARIANT.DARK ? slashDarkColor : slashLightColor,
|
|
88
|
+
marginLeft: slashOffset
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const ColourBubble = /*#__PURE__*/React.forwardRef((_ref6, ref) => {
|
|
92
|
+
let {
|
|
93
|
+
tokens = () => ({}),
|
|
69
94
|
id,
|
|
70
95
|
colourHexCode,
|
|
71
96
|
colourName,
|
|
72
97
|
isSelected,
|
|
73
98
|
onPress,
|
|
74
|
-
showTooltip
|
|
75
|
-
|
|
99
|
+
showTooltip,
|
|
100
|
+
unavailable,
|
|
101
|
+
isDisabled
|
|
102
|
+
} = _ref6;
|
|
76
103
|
const defaultTokens = tokens({
|
|
77
104
|
selected: isSelected
|
|
78
105
|
});
|
|
79
|
-
const resolveColourBubbleTokens = pressState => resolvePressableTokens(tokens, pressState, {});
|
|
80
|
-
const themeTokens =
|
|
81
|
-
const pressable = /*#__PURE__*/
|
|
106
|
+
const resolveColourBubbleTokens = pressState => resolvePressableTokens(tokens, isDisabled ? {} : pressState, {});
|
|
107
|
+
const themeTokens = tokens();
|
|
108
|
+
const pressable = /*#__PURE__*/_jsxs(Pressable, {
|
|
82
109
|
style: state => [selectGeneralBubbleTokens(resolveColourBubbleTokens(state)), isSelected && selectBorderBubbleTokens(defaultTokens)],
|
|
83
110
|
onPress: onPress,
|
|
111
|
+
disabled: isDisabled,
|
|
112
|
+
focusable: !isDisabled,
|
|
84
113
|
accessible: true,
|
|
85
114
|
accessibilityRole: "radio",
|
|
86
115
|
accessibilityLabel: colourName,
|
|
87
116
|
accessibilityState: {
|
|
88
|
-
checked: isSelected
|
|
117
|
+
checked: isSelected,
|
|
118
|
+
disabled: isDisabled
|
|
89
119
|
},
|
|
90
120
|
ref: ref,
|
|
91
121
|
testID: id,
|
|
92
|
-
children: /*#__PURE__*/_jsx(View, {
|
|
122
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
93
123
|
style: [selectInnerBubbleTokens(themeTokens), {
|
|
94
124
|
backgroundColor: colourHexCode
|
|
95
|
-
}]
|
|
96
|
-
|
|
125
|
+
}],
|
|
126
|
+
children: unavailable && /*#__PURE__*/_jsx(View, {
|
|
127
|
+
style: [StyleSheet.absoluteFillObject, selectOverlayStyles(themeTokens)]
|
|
128
|
+
})
|
|
129
|
+
}), unavailable && /*#__PURE__*/_jsx(View, {
|
|
130
|
+
style: [staticStyles.indicator, selectSlashStyles(themeTokens, unavailable)]
|
|
131
|
+
})]
|
|
97
132
|
});
|
|
98
133
|
if (showTooltip) {
|
|
99
134
|
return /*#__PURE__*/_jsx(Tooltip, {
|
|
@@ -135,6 +170,24 @@ ColourBubble.propTypes = {
|
|
|
135
170
|
/**
|
|
136
171
|
* When true, wraps the bubble in a Tooltip that displays the colourName on hover (web only).
|
|
137
172
|
*/
|
|
138
|
-
showTooltip: PropTypes.bool
|
|
173
|
+
showTooltip: PropTypes.bool,
|
|
174
|
+
/**
|
|
175
|
+
* When set, renders a diagonal indicator over the bubble. Accepts either 'dark' or 'light' to determine the colour of the indicator.
|
|
176
|
+
*/
|
|
177
|
+
unavailable: PropTypes.oneOf(Object.values(UNAVAILABLE_VARIANT)),
|
|
178
|
+
/**
|
|
179
|
+
* When true, disables interaction on the bubble.
|
|
180
|
+
*/
|
|
181
|
+
isDisabled: PropTypes.bool
|
|
139
182
|
};
|
|
183
|
+
const staticStyles = StyleSheet.create({
|
|
184
|
+
indicator: {
|
|
185
|
+
position: 'absolute',
|
|
186
|
+
top: '50%',
|
|
187
|
+
height: 2,
|
|
188
|
+
transform: [{
|
|
189
|
+
rotate: '-45deg'
|
|
190
|
+
}]
|
|
191
|
+
}
|
|
192
|
+
});
|
|
140
193
|
export default ColourBubble;
|