carbon-react 147.0.1 → 147.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.
- package/esm/__internal__/fieldset/fieldset.component.js +10 -2
- package/esm/__internal__/fieldset/fieldset.style.d.ts +1 -1
- package/esm/__internal__/fieldset/fieldset.style.js +13 -2
- package/esm/components/checkbox/checkbox-group/checkbox-group.component.js +1 -1
- package/esm/components/numeral-date/numeral-date.component.d.ts +4 -2
- package/esm/components/numeral-date/numeral-date.component.js +14 -4
- package/esm/components/numeral-date/numeral-date.style.d.ts +6 -1
- package/esm/components/numeral-date/numeral-date.style.js +16 -7
- package/esm/components/portrait/__internal__/utils.d.ts +2 -0
- package/esm/components/portrait/__internal__/utils.js +75 -0
- package/esm/components/portrait/portrait.component.d.ts +5 -1
- package/esm/components/portrait/portrait.component.js +8 -2
- package/esm/components/portrait/portrait.style.d.ts +2 -0
- package/esm/components/portrait/portrait.style.js +9 -8
- package/esm/components/profile/profile.component.d.ts +5 -1
- package/esm/components/profile/profile.component.js +6 -1
- package/esm/components/profile/profile.style.d.ts +1 -1
- package/esm/components/radio-button/radio-button-group/radio-button-group.component.js +1 -1
- package/esm/components/switch/switch.component.js +0 -2
- package/esm/components/time/time.component.d.ts +4 -0
- package/esm/components/time/time.component.js +14 -5
- package/esm/components/time/time.style.js +1 -1
- package/lib/__internal__/fieldset/fieldset.component.js +10 -2
- package/lib/__internal__/fieldset/fieldset.style.d.ts +1 -1
- package/lib/__internal__/fieldset/fieldset.style.js +13 -2
- package/lib/components/checkbox/checkbox-group/checkbox-group.component.js +1 -1
- package/lib/components/numeral-date/numeral-date.component.d.ts +4 -2
- package/lib/components/numeral-date/numeral-date.component.js +14 -4
- package/lib/components/numeral-date/numeral-date.style.d.ts +6 -1
- package/lib/components/numeral-date/numeral-date.style.js +16 -7
- package/lib/components/portrait/__internal__/utils.d.ts +2 -0
- package/lib/components/portrait/__internal__/utils.js +81 -0
- package/lib/components/portrait/portrait.component.d.ts +5 -1
- package/lib/components/portrait/portrait.component.js +8 -2
- package/lib/components/portrait/portrait.style.d.ts +2 -0
- package/lib/components/portrait/portrait.style.js +9 -8
- package/lib/components/profile/profile.component.d.ts +5 -1
- package/lib/components/profile/profile.component.js +6 -1
- package/lib/components/profile/profile.style.d.ts +1 -1
- package/lib/components/radio-button/radio-button-group/radio-button-group.component.js +1 -1
- package/lib/components/switch/switch.component.js +0 -2
- package/lib/components/time/time.component.d.ts +4 -0
- package/lib/components/time/time.component.js +14 -5
- package/lib/components/time/time.style.js +1 -1
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ const Fieldset = ({
|
|
|
12
12
|
children,
|
|
13
13
|
inline = false,
|
|
14
14
|
legendWidth,
|
|
15
|
-
legendAlign
|
|
15
|
+
legendAlign,
|
|
16
16
|
legendSpacing = 2,
|
|
17
17
|
error,
|
|
18
18
|
warning,
|
|
@@ -60,6 +60,14 @@ const Fieldset = ({
|
|
|
60
60
|
}
|
|
61
61
|
return null;
|
|
62
62
|
};
|
|
63
|
+
let legendAlignment;
|
|
64
|
+
if (inline && !legendAlign) {
|
|
65
|
+
legendAlignment = "right";
|
|
66
|
+
} else if (!legendAlign) {
|
|
67
|
+
legendAlignment = "left";
|
|
68
|
+
} else {
|
|
69
|
+
legendAlignment = legendAlign;
|
|
70
|
+
}
|
|
63
71
|
return /*#__PURE__*/React.createElement(InputGroupBehaviour, {
|
|
64
72
|
blockGroupBehaviour: blockGroupBehaviour
|
|
65
73
|
}, /*#__PURE__*/React.createElement(StyledFieldset, _extends({
|
|
@@ -73,7 +81,7 @@ const Fieldset = ({
|
|
|
73
81
|
onMouseLeave: onMouseLeave,
|
|
74
82
|
inline: inline,
|
|
75
83
|
width: legendWidth,
|
|
76
|
-
align:
|
|
84
|
+
align: legendAlignment,
|
|
77
85
|
rightPadding: legendSpacing
|
|
78
86
|
}, legendMargin, {
|
|
79
87
|
"data-element": "legend",
|
|
@@ -8,7 +8,7 @@ declare type StyledLegendContentProps = {
|
|
|
8
8
|
isDisabled?: boolean;
|
|
9
9
|
};
|
|
10
10
|
declare const StyledLegendContent: import("styled-components").StyledComponent<"span", any, StyledLegendContentProps, never>;
|
|
11
|
-
declare type StyledLegendProps = {
|
|
11
|
+
export declare type StyledLegendProps = {
|
|
12
12
|
inline?: boolean;
|
|
13
13
|
width?: number;
|
|
14
14
|
align?: "left" | "right";
|
|
@@ -60,17 +60,28 @@ const StyledLegend = styled.legend`
|
|
|
60
60
|
padding: 0;
|
|
61
61
|
font-weight: var(--fontWeights500);
|
|
62
62
|
color: var(--colorsUtilityYin090);
|
|
63
|
+
|
|
64
|
+
${({
|
|
65
|
+
align,
|
|
66
|
+
inline
|
|
67
|
+
}) => align && css`
|
|
68
|
+
text-align: ${align};
|
|
69
|
+
justify-content: ${align === "right" ? "flex-end" : "flex-start"};
|
|
70
|
+
|
|
71
|
+
${!inline && css`
|
|
72
|
+
width: -moz-available;
|
|
73
|
+
`}
|
|
74
|
+
`};
|
|
75
|
+
|
|
63
76
|
${({
|
|
64
77
|
inline,
|
|
65
78
|
width,
|
|
66
|
-
align,
|
|
67
79
|
rightPadding
|
|
68
80
|
}) => inline && css`
|
|
69
81
|
float: left;
|
|
70
82
|
box-sizing: border-box;
|
|
71
83
|
margin: 0;
|
|
72
84
|
${width && `width: ${width}%`};
|
|
73
|
-
justify-content: ${align === "right" ? "flex-end" : "flex-start"};
|
|
74
85
|
padding-right: ${rightPadding === 1 ? "var(--spacing100)" : "var(--spacing200)"};
|
|
75
86
|
`}
|
|
76
87
|
${margin}
|
|
@@ -51,8 +51,10 @@ export interface NumeralDateProps<DateType extends NumeralDateObject = FullDate>
|
|
|
51
51
|
name?: string;
|
|
52
52
|
/** Label */
|
|
53
53
|
label?: string;
|
|
54
|
-
/**
|
|
54
|
+
/** Label alignment */
|
|
55
55
|
labelAlign?: "left" | "right";
|
|
56
|
+
/** Field labels alignment */
|
|
57
|
+
fieldLabelsAlign?: "left" | "right";
|
|
56
58
|
/**
|
|
57
59
|
* Text applied to label help tooltip, will be rendered as
|
|
58
60
|
* hint text when `validationRedesignOptIn` is true.
|
|
@@ -94,5 +96,5 @@ export interface NumeralDateProps<DateType extends NumeralDateObject = FullDate>
|
|
|
94
96
|
isOptional?: boolean;
|
|
95
97
|
}
|
|
96
98
|
export declare type ValidDateFormat = (typeof ALLOWED_DATE_FORMATS)[number];
|
|
97
|
-
export declare const NumeralDate: <DateType extends NumeralDateObject = FullDate>({ dateFormat, defaultValue, disabled, error, warning, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, info, id, name, onBlur, onChange, value, validationOnLabel, label, labelInline, labelWidth, labelAlign, labelHelp, labelSpacing, fieldHelp, adaptiveLabelBreakpoint, required, isOptional, readOnly, size, enableInternalError, enableInternalWarning, tooltipPosition, helpAriaLabel, dayRef, monthRef, yearRef, ...rest }: NumeralDateProps<DateType>) => React.JSX.Element;
|
|
99
|
+
export declare const NumeralDate: <DateType extends NumeralDateObject = FullDate>({ dateFormat, defaultValue, disabled, error, warning, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, info, id, name, onBlur, onChange, value, validationOnLabel, label, labelInline, labelWidth, labelAlign, fieldLabelsAlign, labelHelp, labelSpacing, fieldHelp, adaptiveLabelBreakpoint, required, isOptional, readOnly, size, enableInternalError, enableInternalWarning, tooltipPosition, helpAriaLabel, dayRef, monthRef, yearRef, ...rest }: NumeralDateProps<DateType>) => React.JSX.Element;
|
|
98
100
|
export default NumeralDate;
|
|
@@ -97,6 +97,7 @@ export const NumeralDate = ({
|
|
|
97
97
|
labelInline,
|
|
98
98
|
labelWidth,
|
|
99
99
|
labelAlign,
|
|
100
|
+
fieldLabelsAlign,
|
|
100
101
|
labelHelp,
|
|
101
102
|
labelSpacing,
|
|
102
103
|
fieldHelp,
|
|
@@ -262,9 +263,9 @@ export const NumeralDate = ({
|
|
|
262
263
|
isYearInput: datePart.length === 4,
|
|
263
264
|
hasValidationIconInField: !validationOnLabel && isEnd && validationInField
|
|
264
265
|
}, /*#__PURE__*/React.createElement(Textbox, _extends({
|
|
265
|
-
maxWidth: "fit-content",
|
|
266
266
|
id: inputIds.current[datePart],
|
|
267
267
|
label: getDateLabel(datePart, locale),
|
|
268
|
+
labelAlign: fieldLabelsAlign,
|
|
268
269
|
disabled: disabled,
|
|
269
270
|
readOnly: readOnly,
|
|
270
271
|
error: !!internalError,
|
|
@@ -294,6 +295,9 @@ export const NumeralDate = ({
|
|
|
294
295
|
"data-role": dataRole,
|
|
295
296
|
id: uniqueId,
|
|
296
297
|
legend: label,
|
|
298
|
+
legendMargin: {
|
|
299
|
+
mb: 0
|
|
300
|
+
},
|
|
297
301
|
isRequired: required,
|
|
298
302
|
isOptional: isOptional,
|
|
299
303
|
isDisabled: disabled,
|
|
@@ -302,6 +306,7 @@ export const NumeralDate = ({
|
|
|
302
306
|
warning: validationOnLabel && internalWarning,
|
|
303
307
|
info: validationOnLabel && info,
|
|
304
308
|
inline: inline,
|
|
309
|
+
size: size,
|
|
305
310
|
labelHelp: labelHelp,
|
|
306
311
|
legendAlign: labelAlign,
|
|
307
312
|
legendWidth: labelWidth,
|
|
@@ -309,8 +314,9 @@ export const NumeralDate = ({
|
|
|
309
314
|
validationId: validationId,
|
|
310
315
|
"aria-describedby": ariaDescribedBy
|
|
311
316
|
}, filterStyledSystemMarginProps(rest)), /*#__PURE__*/React.createElement(Box, {
|
|
312
|
-
display: "
|
|
313
|
-
|
|
317
|
+
display: "flex",
|
|
318
|
+
flexDirection: "column",
|
|
319
|
+
mt: inline ? 0 : 1
|
|
314
320
|
}, renderInputs(), fieldHelp && /*#__PURE__*/React.createElement(FieldHelp, {
|
|
315
321
|
id: fieldHelpId
|
|
316
322
|
}, fieldHelp))));
|
|
@@ -321,6 +327,10 @@ export const NumeralDate = ({
|
|
|
321
327
|
"data-role": dataRole,
|
|
322
328
|
id: uniqueId,
|
|
323
329
|
legend: label,
|
|
330
|
+
legendMargin: {
|
|
331
|
+
mb: 0
|
|
332
|
+
},
|
|
333
|
+
legendAlign: labelAlign,
|
|
324
334
|
isRequired: required,
|
|
325
335
|
isOptional: isOptional,
|
|
326
336
|
isDisabled: disabled,
|
|
@@ -330,7 +340,7 @@ export const NumeralDate = ({
|
|
|
330
340
|
id: inputHintId.current
|
|
331
341
|
}, labelHelp), /*#__PURE__*/React.createElement(Box, {
|
|
332
342
|
position: "relative",
|
|
333
|
-
mt: 1
|
|
343
|
+
mt: labelHelp ? 0 : 1
|
|
334
344
|
}, (internalError || internalWarning) && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ValidationMessage, {
|
|
335
345
|
error: internalError,
|
|
336
346
|
warning: internalWarning,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { FieldsetProps } from "../../__internal__/fieldset";
|
|
2
3
|
interface StyledDateFieldProps {
|
|
3
4
|
isYearInput?: boolean;
|
|
4
5
|
hasValidationIconInField: boolean;
|
|
@@ -8,5 +9,9 @@ export declare const StyledNumeralDate: import("styled-components").StyledCompon
|
|
|
8
9
|
name?: string | undefined;
|
|
9
10
|
}, never>;
|
|
10
11
|
export declare const StyledDateField: import("styled-components").StyledComponent<"div", any, StyledDateFieldProps, never>;
|
|
11
|
-
|
|
12
|
+
interface StyledFieldsetProps extends FieldsetProps {
|
|
13
|
+
inline?: boolean;
|
|
14
|
+
size?: "small" | "medium" | "large";
|
|
15
|
+
}
|
|
16
|
+
export declare const StyledFieldset: import("styled-components").StyledComponent<({ legend, children, inline, legendWidth, legendAlign, legendSpacing, error, warning, info, isRequired, blockGroupBehaviour, legendMargin, isDisabled, isOptional, labelHelp, validationId, ...rest }: FieldsetProps) => import("react").JSX.Element, any, StyledFieldsetProps, never>;
|
|
12
17
|
export {};
|
|
@@ -46,17 +46,26 @@ export const StyledDateField = styled.div`
|
|
|
46
46
|
}
|
|
47
47
|
`}
|
|
48
48
|
`;
|
|
49
|
+
// We need to match height of the legend to the input container when it is inline to center it vertically,
|
|
50
|
+
// as Safari does not support display: flex on fieldset elements.
|
|
51
|
+
const sizeHeight = {
|
|
52
|
+
small: "57px",
|
|
53
|
+
medium: "65px",
|
|
54
|
+
large: "73px"
|
|
55
|
+
};
|
|
49
56
|
export const StyledFieldset = styled(Fieldset)`
|
|
50
57
|
${({
|
|
51
|
-
inline
|
|
58
|
+
inline,
|
|
59
|
+
size
|
|
52
60
|
}) => css`
|
|
53
61
|
${inline && css`
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
${StyledLegend} {
|
|
63
|
+
height: ${size && sizeHeight[size]};
|
|
64
|
+
}
|
|
56
65
|
`}
|
|
57
|
-
`}
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
${!inline && css`
|
|
68
|
+
width: min-content;
|
|
69
|
+
`}
|
|
70
|
+
`}
|
|
62
71
|
`;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const getContrastRatio = (luminance1, luminance2) => {
|
|
2
|
+
const [L1, L2] = luminance1 > luminance2 ? [luminance1, luminance2] : [luminance2, luminance1];
|
|
3
|
+
return (L1 + 0.05) / (L2 + 0.05);
|
|
4
|
+
};
|
|
5
|
+
const calculateLuminance = hexColor => {
|
|
6
|
+
const hex = hexColor.replace("#", "");
|
|
7
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
8
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
9
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
10
|
+
const normalize = value => {
|
|
11
|
+
const v = value / 255;
|
|
12
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
13
|
+
};
|
|
14
|
+
const normalizedR = normalize(r);
|
|
15
|
+
const normalizedG = normalize(g);
|
|
16
|
+
const normalizedB = normalize(b);
|
|
17
|
+
const luminance = 0.2126 * normalizedR + 0.7152 * normalizedG + 0.0722 * normalizedB;
|
|
18
|
+
return luminance;
|
|
19
|
+
};
|
|
20
|
+
function getAccessibleForegroundColor(backgroundColor, largeText, strict) {
|
|
21
|
+
const bgLuminance = calculateLuminance(backgroundColor);
|
|
22
|
+
const whiteLuminance = calculateLuminance("#FFFFFF");
|
|
23
|
+
const blackLuminance = calculateLuminance("#000000");
|
|
24
|
+
const whiteContrast = getContrastRatio(bgLuminance, whiteLuminance);
|
|
25
|
+
const blackContrast = getContrastRatio(bgLuminance, blackLuminance);
|
|
26
|
+
const strictThreshold = largeText ? 4.5 : 7.0;
|
|
27
|
+
const nonStrictThreshold = largeText ? 3.0 : 4.5;
|
|
28
|
+
const minContrast = strict ? strictThreshold : nonStrictThreshold;
|
|
29
|
+
|
|
30
|
+
/* istanbul ignore else */
|
|
31
|
+
if (whiteContrast >= minContrast && whiteContrast > blackContrast) {
|
|
32
|
+
return "#FFFFFF";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* istanbul ignore else */
|
|
36
|
+
if (blackContrast >= minContrast) {
|
|
37
|
+
return "var(--colorsUtilityYin090)";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// If no color meets the contrast ratio, return the color with the highest contrast
|
|
41
|
+
// In theory this is possible only if the background color is a shade of grey, but
|
|
42
|
+
// this is a fallback mechanism as finding a colour which fails both contrast ratios
|
|
43
|
+
// is highly unlikely.
|
|
44
|
+
/* istanbul ignore next */
|
|
45
|
+
return whiteContrast > blackContrast ? "#FFFFFF" : "var(--colorsUtilityYin090)";
|
|
46
|
+
}
|
|
47
|
+
const getColoursForPortrait = (backgroundColour,
|
|
48
|
+
// Whether the portrait is on a dark background
|
|
49
|
+
darkBackground = false,
|
|
50
|
+
// Whether the text is large
|
|
51
|
+
largeText = false,
|
|
52
|
+
/**
|
|
53
|
+
* Whether to use strict contrast (i.e., WCAG AAA). If this is false, it uses WCAG AA contrast
|
|
54
|
+
* ratios (4.5:1 for normal text, 3:1 for large text). If true, it uses 7:1 for normal text and
|
|
55
|
+
* 4.5:1 for large text.
|
|
56
|
+
*/
|
|
57
|
+
strict = false,
|
|
58
|
+
// The custom foreground colour, if any
|
|
59
|
+
foregroundColor = undefined) => {
|
|
60
|
+
let fgColor = "var(--colorsUtilityYin090)";
|
|
61
|
+
let bgColor = "var(--colorsUtilityReadOnly400)";
|
|
62
|
+
if (darkBackground && !backgroundColour && !foregroundColor) {
|
|
63
|
+
bgColor = "var(--colorsUtilityYin090)";
|
|
64
|
+
fgColor = "var(--colorsUtilityReadOnly600)";
|
|
65
|
+
}
|
|
66
|
+
if (backgroundColour) {
|
|
67
|
+
bgColor = backgroundColour;
|
|
68
|
+
fgColor = getAccessibleForegroundColor(backgroundColour, largeText, strict);
|
|
69
|
+
}
|
|
70
|
+
if (foregroundColor) {
|
|
71
|
+
fgColor = foregroundColor;
|
|
72
|
+
}
|
|
73
|
+
return `background-color: ${bgColor}; color: ${fgColor};`;
|
|
74
|
+
};
|
|
75
|
+
export default getColoursForPortrait;
|
|
@@ -38,6 +38,10 @@ export interface PortraitProps extends MarginProps {
|
|
|
38
38
|
tooltipBgColor?: string;
|
|
39
39
|
/** [Legacy] Override font color of the Tooltip, provide any color from palette or any valid css color value. */
|
|
40
40
|
tooltipFontColor?: string;
|
|
41
|
+
/** The hex code of the background colour */
|
|
42
|
+
backgroundColor?: string;
|
|
43
|
+
/** The hex code of the foreground colour. This will only take effect if use in conjunction with `backgroundColor` */
|
|
44
|
+
foregroundColor?: string;
|
|
41
45
|
}
|
|
42
|
-
declare const Portrait: ({ alt, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
|
|
46
|
+
declare const Portrait: ({ alt, backgroundColor, foregroundColor, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
|
|
43
47
|
export default Portrait;
|
|
@@ -7,6 +7,8 @@ import { StyledCustomImg, StyledIcon, StyledPortraitContainer, StyledPortraitIni
|
|
|
7
7
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
8
8
|
const Portrait = ({
|
|
9
9
|
alt,
|
|
10
|
+
backgroundColor,
|
|
11
|
+
foregroundColor = undefined,
|
|
10
12
|
name,
|
|
11
13
|
darkBackground = false,
|
|
12
14
|
iconType = "individual",
|
|
@@ -66,7 +68,9 @@ const Portrait = ({
|
|
|
66
68
|
hasValidImg: hasValidImg,
|
|
67
69
|
darkBackground: darkBackground,
|
|
68
70
|
size: size,
|
|
69
|
-
shape: shape
|
|
71
|
+
shape: shape,
|
|
72
|
+
backgroundColor: backgroundColor,
|
|
73
|
+
foregroundColor: foregroundColor
|
|
70
74
|
}), portrait));
|
|
71
75
|
}
|
|
72
76
|
return /*#__PURE__*/React.createElement(StyledPortraitContainer, _extends({}, filterStyledSystemMarginProps(rest), {
|
|
@@ -75,7 +79,9 @@ const Portrait = ({
|
|
|
75
79
|
hasValidImg: hasValidImg,
|
|
76
80
|
darkBackground: darkBackground,
|
|
77
81
|
size: size,
|
|
78
|
-
shape: shape
|
|
82
|
+
shape: shape,
|
|
83
|
+
backgroundColor: backgroundColor,
|
|
84
|
+
foregroundColor: foregroundColor
|
|
79
85
|
}), portrait);
|
|
80
86
|
};
|
|
81
87
|
return renderComponent();
|
|
@@ -2,6 +2,8 @@ import React from "react";
|
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
3
|
import { PortraitSizes, PortraitShapes } from "./portrait.component";
|
|
4
4
|
declare type StyledPortraitProps = {
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
foregroundColor?: string;
|
|
5
7
|
darkBackground?: boolean;
|
|
6
8
|
size: PortraitSizes;
|
|
7
9
|
shape?: PortraitShapes;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import styled from "styled-components";
|
|
2
2
|
import { margin } from "styled-system";
|
|
3
|
-
import BaseTheme from "../../style/themes/base";
|
|
4
3
|
import Icon from "../icon";
|
|
5
|
-
import { PORTRAIT_SIZE_PARAMS } from "./portrait.config";
|
|
6
4
|
import profileConfigSizes from "../profile/profile.config";
|
|
5
|
+
import BaseTheme from "../../style/themes/base";
|
|
6
|
+
import { PORTRAIT_SIZE_PARAMS } from "./portrait.config";
|
|
7
|
+
import getColoursForPortrait from "./__internal__/utils";
|
|
7
8
|
export const StyledPortraitInitials = styled.div`
|
|
8
9
|
font-weight: 500;
|
|
9
10
|
font-size: ${({
|
|
@@ -37,12 +38,12 @@ export const StyledIcon = styled(Icon)`
|
|
|
37
38
|
}
|
|
38
39
|
`;
|
|
39
40
|
export const StyledPortraitContainer = styled.div`
|
|
40
|
-
|
|
41
|
-
darkBackground
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}) => darkBackground
|
|
41
|
+
${({
|
|
42
|
+
darkBackground,
|
|
43
|
+
backgroundColor,
|
|
44
|
+
size,
|
|
45
|
+
foregroundColor
|
|
46
|
+
}) => getColoursForPortrait(backgroundColor, darkBackground, !["XS", "S"].includes(size), true, foregroundColor)};
|
|
46
47
|
${({
|
|
47
48
|
hasValidImg,
|
|
48
49
|
size
|
|
@@ -24,6 +24,10 @@ export interface ProfileProps extends MarginProps {
|
|
|
24
24
|
size?: ProfileSize;
|
|
25
25
|
/** Use a dark background. */
|
|
26
26
|
darkBackground?: boolean;
|
|
27
|
+
/** The hex code of the background colour to be passed to the avatar */
|
|
28
|
+
backgroundColor?: string;
|
|
29
|
+
/** The hex code of the foreground colour to be passed to the avatar. Must be used in conjunction with `backgroundColor` */
|
|
30
|
+
foregroundColor?: string;
|
|
27
31
|
}
|
|
28
|
-
export declare const Profile: ({ src, alt, className, initials, name, size, email, text, darkBackground, ...props }: ProfileProps) => React.JSX.Element;
|
|
32
|
+
export declare const Profile: ({ src, alt, className, initials, name, size, email, text, darkBackground, backgroundColor, foregroundColor, ...props }: ProfileProps) => React.JSX.Element;
|
|
29
33
|
export default Profile;
|
|
@@ -21,6 +21,8 @@ export const Profile = ({
|
|
|
21
21
|
email,
|
|
22
22
|
text,
|
|
23
23
|
darkBackground,
|
|
24
|
+
backgroundColor,
|
|
25
|
+
foregroundColor,
|
|
24
26
|
...props
|
|
25
27
|
}) => {
|
|
26
28
|
const getInitials = () => {
|
|
@@ -32,7 +34,10 @@ export const Profile = ({
|
|
|
32
34
|
alt,
|
|
33
35
|
name,
|
|
34
36
|
initials: getInitials(),
|
|
35
|
-
size
|
|
37
|
+
size,
|
|
38
|
+
backgroundColor,
|
|
39
|
+
foregroundColor,
|
|
40
|
+
"data-role": "profile-portrait"
|
|
36
41
|
};
|
|
37
42
|
const avatar = () => {
|
|
38
43
|
if (src) {
|
|
@@ -10,5 +10,5 @@ declare const ProfileEmailStyle: import("styled-components").StyledComponent<imp
|
|
|
10
10
|
declare const ProfileTextStyle: import("styled-components").StyledComponent<"span", any, ProfileSProps, never>;
|
|
11
11
|
declare const ProfileStyle: import("styled-components").StyledComponent<"div", any, Pick<ProfileSProps, "darkBackground" | "hasSrc">, never>;
|
|
12
12
|
declare const ProfileDetailsStyle: import("styled-components").StyledComponent<"div", any, Pick<ProfileSProps, "size" | "hasSrc">, never>;
|
|
13
|
-
declare const ProfileAvatarStyle: import("styled-components").StyledComponent<({ alt, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: import("../portrait").PortraitProps) => import("react").JSX.Element, any, {}, never>;
|
|
13
|
+
declare const ProfileAvatarStyle: import("styled-components").StyledComponent<({ alt, backgroundColor, foregroundColor, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: import("../portrait").PortraitProps) => import("react").JSX.Element, any, {}, never>;
|
|
14
14
|
export { ProfileStyle, ProfileNameStyle, ProfileDetailsStyle, ProfileAvatarStyle, ProfileEmailStyle, ProfileTextStyle, };
|
|
@@ -194,8 +194,6 @@ const Switch = /*#__PURE__*/React.forwardRef(({
|
|
|
194
194
|
width: labelInline ? "100%" : "auto"
|
|
195
195
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
196
196
|
"data-role": "label-wrapper"
|
|
197
|
-
// width={labelInline ? rest.labelWidth : 30}
|
|
198
|
-
// minWidth={label && labelInline ? "32px" : 0}
|
|
199
197
|
}, /*#__PURE__*/React.createElement(Label, {
|
|
200
198
|
isDarkBackground: isDarkBackground,
|
|
201
199
|
labelId: labelId.current,
|
|
@@ -28,6 +28,10 @@ interface TimeInputProps extends Omit<TagProps, "data-component">, Omit<Validati
|
|
|
28
28
|
export interface TimeProps extends Omit<TagProps, "data-component">, MarginProps {
|
|
29
29
|
/** Label text for the component */
|
|
30
30
|
label?: string;
|
|
31
|
+
/** Label alignment */
|
|
32
|
+
labelAlign?: "left" | "right";
|
|
33
|
+
/** Field labels alignment */
|
|
34
|
+
fieldLabelsAlign?: "left" | "right";
|
|
31
35
|
/** Sets the size of the inputs */
|
|
32
36
|
size?: Sizes;
|
|
33
37
|
/** Additional hint text rendered above the input elements */
|
|
@@ -15,6 +15,8 @@ import { StyledLabel as Label, StyledHintText as Hint } from "./time.style";
|
|
|
15
15
|
import { TimeToggle } from "./__internal__/time-toggle";
|
|
16
16
|
const Time = /*#__PURE__*/React.forwardRef(({
|
|
17
17
|
label,
|
|
18
|
+
labelAlign,
|
|
19
|
+
fieldLabelsAlign,
|
|
18
20
|
size = "medium",
|
|
19
21
|
inputHint,
|
|
20
22
|
hoursInputProps = {},
|
|
@@ -141,7 +143,8 @@ const Time = /*#__PURE__*/React.forwardRef(({
|
|
|
141
143
|
legendMargin: {
|
|
142
144
|
mb: 0
|
|
143
145
|
},
|
|
144
|
-
width: "
|
|
146
|
+
width: "min-content",
|
|
147
|
+
legendAlign: labelAlign,
|
|
145
148
|
isRequired: required,
|
|
146
149
|
isOptional: isOptional,
|
|
147
150
|
isDisabled: disabled,
|
|
@@ -153,7 +156,8 @@ const Time = /*#__PURE__*/React.forwardRef(({
|
|
|
153
156
|
id: inputHintId.current,
|
|
154
157
|
isDisabled: disabled
|
|
155
158
|
}, inputHint), /*#__PURE__*/React.createElement(Box, {
|
|
156
|
-
position: "relative"
|
|
159
|
+
position: "relative",
|
|
160
|
+
mt: inputHint ? 0 : 1
|
|
157
161
|
}, /*#__PURE__*/React.createElement(ValidationMessage, {
|
|
158
162
|
validationId: validationId,
|
|
159
163
|
error: error,
|
|
@@ -165,7 +169,8 @@ const Time = /*#__PURE__*/React.forwardRef(({
|
|
|
165
169
|
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Label, {
|
|
166
170
|
"aria-label": hrsAriaLabel,
|
|
167
171
|
htmlFor: internalHrsId.current,
|
|
168
|
-
disabled: disabled
|
|
172
|
+
disabled: disabled,
|
|
173
|
+
align: fieldLabelsAlign
|
|
169
174
|
}, hrsLabel), /*#__PURE__*/React.createElement(Number, _extends({}, hoursInputProps, {
|
|
170
175
|
label: undefined,
|
|
171
176
|
"data-component": "hours",
|
|
@@ -192,7 +197,8 @@ const Time = /*#__PURE__*/React.forwardRef(({
|
|
|
192
197
|
}, ":")), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Label, {
|
|
193
198
|
"aria-label": minsAriaLabel,
|
|
194
199
|
htmlFor: internalMinsId.current,
|
|
195
|
-
disabled: disabled
|
|
200
|
+
disabled: disabled,
|
|
201
|
+
align: fieldLabelsAlign
|
|
196
202
|
}, minsLabel), /*#__PURE__*/React.createElement(Number, _extends({}, minutesInputProps, {
|
|
197
203
|
label: undefined,
|
|
198
204
|
"data-component": "minutes",
|
|
@@ -209,7 +215,8 @@ const Time = /*#__PURE__*/React.forwardRef(({
|
|
|
209
215
|
}))), showToggle && /*#__PURE__*/React.createElement(Box, {
|
|
210
216
|
display: "flex",
|
|
211
217
|
flexDirection: "column",
|
|
212
|
-
justifyContent: "flex-end"
|
|
218
|
+
justifyContent: "flex-end",
|
|
219
|
+
width: "max-content"
|
|
213
220
|
}, /*#__PURE__*/React.createElement(TimeToggle, {
|
|
214
221
|
toggleProps: toggleProps,
|
|
215
222
|
size: size,
|
|
@@ -224,6 +231,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
224
231
|
"data-element": PropTypes.string,
|
|
225
232
|
"data-role": PropTypes.string,
|
|
226
233
|
"disabled": PropTypes.bool,
|
|
234
|
+
"fieldLabelsAlign": PropTypes.oneOf(["left", "right"]),
|
|
227
235
|
"hoursInputProps": PropTypes.shape({
|
|
228
236
|
"aria-label": PropTypes.string,
|
|
229
237
|
"data-element": PropTypes.string,
|
|
@@ -236,6 +244,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
236
244
|
"inputHint": PropTypes.string,
|
|
237
245
|
"isOptional": PropTypes.bool,
|
|
238
246
|
"label": PropTypes.string,
|
|
247
|
+
"labelAlign": PropTypes.oneOf(["left", "right"]),
|
|
239
248
|
"m": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
|
|
240
249
|
"__@toStringTag": PropTypes.string.isRequired,
|
|
241
250
|
"description": PropTypes.string,
|
|
@@ -11,7 +11,7 @@ export const StyledHintText = styled.div`
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
margin-top: var(--spacing000);
|
|
14
|
-
margin-bottom: var(--
|
|
14
|
+
margin-bottom: var(--spacing100);
|
|
15
15
|
color: ${({
|
|
16
16
|
isDisabled
|
|
17
17
|
}) => isDisabled ? "var(--colorsUtilityYin030)" : "var(--colorsUtilityYin055)"};
|
|
@@ -21,7 +21,7 @@ const Fieldset = ({
|
|
|
21
21
|
children,
|
|
22
22
|
inline = false,
|
|
23
23
|
legendWidth,
|
|
24
|
-
legendAlign
|
|
24
|
+
legendAlign,
|
|
25
25
|
legendSpacing = 2,
|
|
26
26
|
error,
|
|
27
27
|
warning,
|
|
@@ -69,6 +69,14 @@ const Fieldset = ({
|
|
|
69
69
|
}
|
|
70
70
|
return null;
|
|
71
71
|
};
|
|
72
|
+
let legendAlignment;
|
|
73
|
+
if (inline && !legendAlign) {
|
|
74
|
+
legendAlignment = "right";
|
|
75
|
+
} else if (!legendAlign) {
|
|
76
|
+
legendAlignment = "left";
|
|
77
|
+
} else {
|
|
78
|
+
legendAlignment = legendAlign;
|
|
79
|
+
}
|
|
72
80
|
return /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputGroupBehaviour, {
|
|
73
81
|
blockGroupBehaviour: blockGroupBehaviour
|
|
74
82
|
}, /*#__PURE__*/_react.default.createElement(_fieldset.StyledFieldset, _extends({
|
|
@@ -82,7 +90,7 @@ const Fieldset = ({
|
|
|
82
90
|
onMouseLeave: onMouseLeave,
|
|
83
91
|
inline: inline,
|
|
84
92
|
width: legendWidth,
|
|
85
|
-
align:
|
|
93
|
+
align: legendAlignment,
|
|
86
94
|
rightPadding: legendSpacing
|
|
87
95
|
}, legendMargin, {
|
|
88
96
|
"data-element": "legend",
|
|
@@ -8,7 +8,7 @@ declare type StyledLegendContentProps = {
|
|
|
8
8
|
isDisabled?: boolean;
|
|
9
9
|
};
|
|
10
10
|
declare const StyledLegendContent: import("styled-components").StyledComponent<"span", any, StyledLegendContentProps, never>;
|
|
11
|
-
declare type StyledLegendProps = {
|
|
11
|
+
export declare type StyledLegendProps = {
|
|
12
12
|
inline?: boolean;
|
|
13
13
|
width?: number;
|
|
14
14
|
align?: "left" | "right";
|
|
@@ -69,17 +69,28 @@ const StyledLegend = exports.StyledLegend = _styledComponents.default.legend`
|
|
|
69
69
|
padding: 0;
|
|
70
70
|
font-weight: var(--fontWeights500);
|
|
71
71
|
color: var(--colorsUtilityYin090);
|
|
72
|
+
|
|
73
|
+
${({
|
|
74
|
+
align,
|
|
75
|
+
inline
|
|
76
|
+
}) => align && (0, _styledComponents.css)`
|
|
77
|
+
text-align: ${align};
|
|
78
|
+
justify-content: ${align === "right" ? "flex-end" : "flex-start"};
|
|
79
|
+
|
|
80
|
+
${!inline && (0, _styledComponents.css)`
|
|
81
|
+
width: -moz-available;
|
|
82
|
+
`}
|
|
83
|
+
`};
|
|
84
|
+
|
|
72
85
|
${({
|
|
73
86
|
inline,
|
|
74
87
|
width,
|
|
75
|
-
align,
|
|
76
88
|
rightPadding
|
|
77
89
|
}) => inline && (0, _styledComponents.css)`
|
|
78
90
|
float: left;
|
|
79
91
|
box-sizing: border-box;
|
|
80
92
|
margin: 0;
|
|
81
93
|
${width && `width: ${width}%`};
|
|
82
|
-
justify-content: ${align === "right" ? "flex-end" : "flex-start"};
|
|
83
94
|
padding-right: ${rightPadding === 1 ? "var(--spacing100)" : "var(--spacing200)"};
|
|
84
95
|
`}
|
|
85
96
|
${_styledSystem.margin}
|
|
@@ -51,8 +51,10 @@ export interface NumeralDateProps<DateType extends NumeralDateObject = FullDate>
|
|
|
51
51
|
name?: string;
|
|
52
52
|
/** Label */
|
|
53
53
|
label?: string;
|
|
54
|
-
/**
|
|
54
|
+
/** Label alignment */
|
|
55
55
|
labelAlign?: "left" | "right";
|
|
56
|
+
/** Field labels alignment */
|
|
57
|
+
fieldLabelsAlign?: "left" | "right";
|
|
56
58
|
/**
|
|
57
59
|
* Text applied to label help tooltip, will be rendered as
|
|
58
60
|
* hint text when `validationRedesignOptIn` is true.
|
|
@@ -94,5 +96,5 @@ export interface NumeralDateProps<DateType extends NumeralDateObject = FullDate>
|
|
|
94
96
|
isOptional?: boolean;
|
|
95
97
|
}
|
|
96
98
|
export declare type ValidDateFormat = (typeof ALLOWED_DATE_FORMATS)[number];
|
|
97
|
-
export declare const NumeralDate: <DateType extends NumeralDateObject = FullDate>({ dateFormat, defaultValue, disabled, error, warning, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, info, id, name, onBlur, onChange, value, validationOnLabel, label, labelInline, labelWidth, labelAlign, labelHelp, labelSpacing, fieldHelp, adaptiveLabelBreakpoint, required, isOptional, readOnly, size, enableInternalError, enableInternalWarning, tooltipPosition, helpAriaLabel, dayRef, monthRef, yearRef, ...rest }: NumeralDateProps<DateType>) => React.JSX.Element;
|
|
99
|
+
export declare const NumeralDate: <DateType extends NumeralDateObject = FullDate>({ dateFormat, defaultValue, disabled, error, warning, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, info, id, name, onBlur, onChange, value, validationOnLabel, label, labelInline, labelWidth, labelAlign, fieldLabelsAlign, labelHelp, labelSpacing, fieldHelp, adaptiveLabelBreakpoint, required, isOptional, readOnly, size, enableInternalError, enableInternalWarning, tooltipPosition, helpAriaLabel, dayRef, monthRef, yearRef, ...rest }: NumeralDateProps<DateType>) => React.JSX.Element;
|
|
98
100
|
export default NumeralDate;
|
|
@@ -106,6 +106,7 @@ const NumeralDate = ({
|
|
|
106
106
|
labelInline,
|
|
107
107
|
labelWidth,
|
|
108
108
|
labelAlign,
|
|
109
|
+
fieldLabelsAlign,
|
|
109
110
|
labelHelp,
|
|
110
111
|
labelSpacing,
|
|
111
112
|
fieldHelp,
|
|
@@ -271,9 +272,9 @@ const NumeralDate = ({
|
|
|
271
272
|
isYearInput: datePart.length === 4,
|
|
272
273
|
hasValidationIconInField: !validationOnLabel && isEnd && validationInField
|
|
273
274
|
}, /*#__PURE__*/_react.default.createElement(_textbox.default, _extends({
|
|
274
|
-
maxWidth: "fit-content",
|
|
275
275
|
id: inputIds.current[datePart],
|
|
276
276
|
label: getDateLabel(datePart, locale),
|
|
277
|
+
labelAlign: fieldLabelsAlign,
|
|
277
278
|
disabled: disabled,
|
|
278
279
|
readOnly: readOnly,
|
|
279
280
|
error: !!internalError,
|
|
@@ -303,6 +304,9 @@ const NumeralDate = ({
|
|
|
303
304
|
"data-role": dataRole,
|
|
304
305
|
id: uniqueId,
|
|
305
306
|
legend: label,
|
|
307
|
+
legendMargin: {
|
|
308
|
+
mb: 0
|
|
309
|
+
},
|
|
306
310
|
isRequired: required,
|
|
307
311
|
isOptional: isOptional,
|
|
308
312
|
isDisabled: disabled,
|
|
@@ -311,6 +315,7 @@ const NumeralDate = ({
|
|
|
311
315
|
warning: validationOnLabel && internalWarning,
|
|
312
316
|
info: validationOnLabel && info,
|
|
313
317
|
inline: inline,
|
|
318
|
+
size: size,
|
|
314
319
|
labelHelp: labelHelp,
|
|
315
320
|
legendAlign: labelAlign,
|
|
316
321
|
legendWidth: labelWidth,
|
|
@@ -318,8 +323,9 @@ const NumeralDate = ({
|
|
|
318
323
|
validationId: validationId,
|
|
319
324
|
"aria-describedby": ariaDescribedBy
|
|
320
325
|
}, (0, _utils.filterStyledSystemMarginProps)(rest)), /*#__PURE__*/_react.default.createElement(_box.default, {
|
|
321
|
-
display: "
|
|
322
|
-
|
|
326
|
+
display: "flex",
|
|
327
|
+
flexDirection: "column",
|
|
328
|
+
mt: inline ? 0 : 1
|
|
323
329
|
}, renderInputs(), fieldHelp && /*#__PURE__*/_react.default.createElement(_fieldHelp.default, {
|
|
324
330
|
id: fieldHelpId
|
|
325
331
|
}, fieldHelp))));
|
|
@@ -330,6 +336,10 @@ const NumeralDate = ({
|
|
|
330
336
|
"data-role": dataRole,
|
|
331
337
|
id: uniqueId,
|
|
332
338
|
legend: label,
|
|
339
|
+
legendMargin: {
|
|
340
|
+
mb: 0
|
|
341
|
+
},
|
|
342
|
+
legendAlign: labelAlign,
|
|
333
343
|
isRequired: required,
|
|
334
344
|
isOptional: isOptional,
|
|
335
345
|
isDisabled: disabled,
|
|
@@ -339,7 +349,7 @@ const NumeralDate = ({
|
|
|
339
349
|
id: inputHintId.current
|
|
340
350
|
}, labelHelp), /*#__PURE__*/_react.default.createElement(_box.default, {
|
|
341
351
|
position: "relative",
|
|
342
|
-
mt: 1
|
|
352
|
+
mt: labelHelp ? 0 : 1
|
|
343
353
|
}, (internalError || internalWarning) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_validationMessage.default, {
|
|
344
354
|
error: internalError,
|
|
345
355
|
warning: internalWarning,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { FieldsetProps } from "../../__internal__/fieldset";
|
|
2
3
|
interface StyledDateFieldProps {
|
|
3
4
|
isYearInput?: boolean;
|
|
4
5
|
hasValidationIconInField: boolean;
|
|
@@ -8,5 +9,9 @@ export declare const StyledNumeralDate: import("styled-components").StyledCompon
|
|
|
8
9
|
name?: string | undefined;
|
|
9
10
|
}, never>;
|
|
10
11
|
export declare const StyledDateField: import("styled-components").StyledComponent<"div", any, StyledDateFieldProps, never>;
|
|
11
|
-
|
|
12
|
+
interface StyledFieldsetProps extends FieldsetProps {
|
|
13
|
+
inline?: boolean;
|
|
14
|
+
size?: "small" | "medium" | "large";
|
|
15
|
+
}
|
|
16
|
+
export declare const StyledFieldset: import("styled-components").StyledComponent<({ legend, children, inline, legendWidth, legendAlign, legendSpacing, error, warning, info, isRequired, blockGroupBehaviour, legendMargin, isDisabled, isOptional, labelHelp, validationId, ...rest }: FieldsetProps) => import("react").JSX.Element, any, StyledFieldsetProps, never>;
|
|
12
17
|
export {};
|
|
@@ -55,17 +55,26 @@ const StyledDateField = exports.StyledDateField = _styledComponents.default.div`
|
|
|
55
55
|
}
|
|
56
56
|
`}
|
|
57
57
|
`;
|
|
58
|
+
// We need to match height of the legend to the input container when it is inline to center it vertically,
|
|
59
|
+
// as Safari does not support display: flex on fieldset elements.
|
|
60
|
+
const sizeHeight = {
|
|
61
|
+
small: "57px",
|
|
62
|
+
medium: "65px",
|
|
63
|
+
large: "73px"
|
|
64
|
+
};
|
|
58
65
|
const StyledFieldset = exports.StyledFieldset = (0, _styledComponents.default)(_fieldset.default)`
|
|
59
66
|
${({
|
|
60
|
-
inline
|
|
67
|
+
inline,
|
|
68
|
+
size
|
|
61
69
|
}) => (0, _styledComponents.css)`
|
|
62
70
|
${inline && (0, _styledComponents.css)`
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
${_fieldset2.StyledLegend} {
|
|
72
|
+
height: ${size && sizeHeight[size]};
|
|
73
|
+
}
|
|
65
74
|
`}
|
|
66
|
-
`}
|
|
67
75
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
${!inline && (0, _styledComponents.css)`
|
|
77
|
+
width: min-content;
|
|
78
|
+
`}
|
|
79
|
+
`}
|
|
71
80
|
`;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const getContrastRatio = (luminance1, luminance2) => {
|
|
8
|
+
const [L1, L2] = luminance1 > luminance2 ? [luminance1, luminance2] : [luminance2, luminance1];
|
|
9
|
+
return (L1 + 0.05) / (L2 + 0.05);
|
|
10
|
+
};
|
|
11
|
+
const calculateLuminance = hexColor => {
|
|
12
|
+
const hex = hexColor.replace("#", "");
|
|
13
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
14
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
15
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
16
|
+
const normalize = value => {
|
|
17
|
+
const v = value / 255;
|
|
18
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
19
|
+
};
|
|
20
|
+
const normalizedR = normalize(r);
|
|
21
|
+
const normalizedG = normalize(g);
|
|
22
|
+
const normalizedB = normalize(b);
|
|
23
|
+
const luminance = 0.2126 * normalizedR + 0.7152 * normalizedG + 0.0722 * normalizedB;
|
|
24
|
+
return luminance;
|
|
25
|
+
};
|
|
26
|
+
function getAccessibleForegroundColor(backgroundColor, largeText, strict) {
|
|
27
|
+
const bgLuminance = calculateLuminance(backgroundColor);
|
|
28
|
+
const whiteLuminance = calculateLuminance("#FFFFFF");
|
|
29
|
+
const blackLuminance = calculateLuminance("#000000");
|
|
30
|
+
const whiteContrast = getContrastRatio(bgLuminance, whiteLuminance);
|
|
31
|
+
const blackContrast = getContrastRatio(bgLuminance, blackLuminance);
|
|
32
|
+
const strictThreshold = largeText ? 4.5 : 7.0;
|
|
33
|
+
const nonStrictThreshold = largeText ? 3.0 : 4.5;
|
|
34
|
+
const minContrast = strict ? strictThreshold : nonStrictThreshold;
|
|
35
|
+
|
|
36
|
+
/* istanbul ignore else */
|
|
37
|
+
if (whiteContrast >= minContrast && whiteContrast > blackContrast) {
|
|
38
|
+
return "#FFFFFF";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* istanbul ignore else */
|
|
42
|
+
if (blackContrast >= minContrast) {
|
|
43
|
+
return "var(--colorsUtilityYin090)";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// If no color meets the contrast ratio, return the color with the highest contrast
|
|
47
|
+
// In theory this is possible only if the background color is a shade of grey, but
|
|
48
|
+
// this is a fallback mechanism as finding a colour which fails both contrast ratios
|
|
49
|
+
// is highly unlikely.
|
|
50
|
+
/* istanbul ignore next */
|
|
51
|
+
return whiteContrast > blackContrast ? "#FFFFFF" : "var(--colorsUtilityYin090)";
|
|
52
|
+
}
|
|
53
|
+
const getColoursForPortrait = (backgroundColour,
|
|
54
|
+
// Whether the portrait is on a dark background
|
|
55
|
+
darkBackground = false,
|
|
56
|
+
// Whether the text is large
|
|
57
|
+
largeText = false,
|
|
58
|
+
/**
|
|
59
|
+
* Whether to use strict contrast (i.e., WCAG AAA). If this is false, it uses WCAG AA contrast
|
|
60
|
+
* ratios (4.5:1 for normal text, 3:1 for large text). If true, it uses 7:1 for normal text and
|
|
61
|
+
* 4.5:1 for large text.
|
|
62
|
+
*/
|
|
63
|
+
strict = false,
|
|
64
|
+
// The custom foreground colour, if any
|
|
65
|
+
foregroundColor = undefined) => {
|
|
66
|
+
let fgColor = "var(--colorsUtilityYin090)";
|
|
67
|
+
let bgColor = "var(--colorsUtilityReadOnly400)";
|
|
68
|
+
if (darkBackground && !backgroundColour && !foregroundColor) {
|
|
69
|
+
bgColor = "var(--colorsUtilityYin090)";
|
|
70
|
+
fgColor = "var(--colorsUtilityReadOnly600)";
|
|
71
|
+
}
|
|
72
|
+
if (backgroundColour) {
|
|
73
|
+
bgColor = backgroundColour;
|
|
74
|
+
fgColor = getAccessibleForegroundColor(backgroundColour, largeText, strict);
|
|
75
|
+
}
|
|
76
|
+
if (foregroundColor) {
|
|
77
|
+
fgColor = foregroundColor;
|
|
78
|
+
}
|
|
79
|
+
return `background-color: ${bgColor}; color: ${fgColor};`;
|
|
80
|
+
};
|
|
81
|
+
var _default = exports.default = getColoursForPortrait;
|
|
@@ -38,6 +38,10 @@ export interface PortraitProps extends MarginProps {
|
|
|
38
38
|
tooltipBgColor?: string;
|
|
39
39
|
/** [Legacy] Override font color of the Tooltip, provide any color from palette or any valid css color value. */
|
|
40
40
|
tooltipFontColor?: string;
|
|
41
|
+
/** The hex code of the background colour */
|
|
42
|
+
backgroundColor?: string;
|
|
43
|
+
/** The hex code of the foreground colour. This will only take effect if use in conjunction with `backgroundColor` */
|
|
44
|
+
foregroundColor?: string;
|
|
41
45
|
}
|
|
42
|
-
declare const Portrait: ({ alt, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
|
|
46
|
+
declare const Portrait: ({ alt, backgroundColor, foregroundColor, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
|
|
43
47
|
export default Portrait;
|
|
@@ -16,6 +16,8 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
16
16
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
17
17
|
const Portrait = ({
|
|
18
18
|
alt,
|
|
19
|
+
backgroundColor,
|
|
20
|
+
foregroundColor = undefined,
|
|
19
21
|
name,
|
|
20
22
|
darkBackground = false,
|
|
21
23
|
iconType = "individual",
|
|
@@ -75,7 +77,9 @@ const Portrait = ({
|
|
|
75
77
|
hasValidImg: hasValidImg,
|
|
76
78
|
darkBackground: darkBackground,
|
|
77
79
|
size: size,
|
|
78
|
-
shape: shape
|
|
80
|
+
shape: shape,
|
|
81
|
+
backgroundColor: backgroundColor,
|
|
82
|
+
foregroundColor: foregroundColor
|
|
79
83
|
}), portrait));
|
|
80
84
|
}
|
|
81
85
|
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitContainer, _extends({}, (0, _utils.filterStyledSystemMarginProps)(rest), {
|
|
@@ -84,7 +88,9 @@ const Portrait = ({
|
|
|
84
88
|
hasValidImg: hasValidImg,
|
|
85
89
|
darkBackground: darkBackground,
|
|
86
90
|
size: size,
|
|
87
|
-
shape: shape
|
|
91
|
+
shape: shape,
|
|
92
|
+
backgroundColor: backgroundColor,
|
|
93
|
+
foregroundColor: foregroundColor
|
|
88
94
|
}), portrait);
|
|
89
95
|
};
|
|
90
96
|
return renderComponent();
|
|
@@ -2,6 +2,8 @@ import React from "react";
|
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
3
|
import { PortraitSizes, PortraitShapes } from "./portrait.component";
|
|
4
4
|
declare type StyledPortraitProps = {
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
foregroundColor?: string;
|
|
5
7
|
darkBackground?: boolean;
|
|
6
8
|
size: PortraitSizes;
|
|
7
9
|
shape?: PortraitShapes;
|
|
@@ -6,10 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.StyledPortraitInitials = exports.StyledPortraitContainer = exports.StyledIcon = exports.StyledCustomImg = void 0;
|
|
7
7
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
8
|
var _styledSystem = require("styled-system");
|
|
9
|
-
var _base = _interopRequireDefault(require("../../style/themes/base"));
|
|
10
9
|
var _icon = _interopRequireDefault(require("../icon"));
|
|
11
|
-
var _portrait = require("./portrait.config");
|
|
12
10
|
var _profile = _interopRequireDefault(require("../profile/profile.config"));
|
|
11
|
+
var _base = _interopRequireDefault(require("../../style/themes/base"));
|
|
12
|
+
var _portrait = require("./portrait.config");
|
|
13
|
+
var _utils = _interopRequireDefault(require("./__internal__/utils"));
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
const StyledPortraitInitials = exports.StyledPortraitInitials = _styledComponents.default.div`
|
|
15
16
|
font-weight: 500;
|
|
@@ -44,12 +45,12 @@ const StyledIcon = exports.StyledIcon = (0, _styledComponents.default)(_icon.def
|
|
|
44
45
|
}
|
|
45
46
|
`;
|
|
46
47
|
const StyledPortraitContainer = exports.StyledPortraitContainer = _styledComponents.default.div`
|
|
47
|
-
|
|
48
|
-
darkBackground
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}) => darkBackground
|
|
48
|
+
${({
|
|
49
|
+
darkBackground,
|
|
50
|
+
backgroundColor,
|
|
51
|
+
size,
|
|
52
|
+
foregroundColor
|
|
53
|
+
}) => (0, _utils.default)(backgroundColor, darkBackground, !["XS", "S"].includes(size), true, foregroundColor)};
|
|
53
54
|
${({
|
|
54
55
|
hasValidImg,
|
|
55
56
|
size
|
|
@@ -24,6 +24,10 @@ export interface ProfileProps extends MarginProps {
|
|
|
24
24
|
size?: ProfileSize;
|
|
25
25
|
/** Use a dark background. */
|
|
26
26
|
darkBackground?: boolean;
|
|
27
|
+
/** The hex code of the background colour to be passed to the avatar */
|
|
28
|
+
backgroundColor?: string;
|
|
29
|
+
/** The hex code of the foreground colour to be passed to the avatar. Must be used in conjunction with `backgroundColor` */
|
|
30
|
+
foregroundColor?: string;
|
|
27
31
|
}
|
|
28
|
-
export declare const Profile: ({ src, alt, className, initials, name, size, email, text, darkBackground, ...props }: ProfileProps) => React.JSX.Element;
|
|
32
|
+
export declare const Profile: ({ src, alt, className, initials, name, size, email, text, darkBackground, backgroundColor, foregroundColor, ...props }: ProfileProps) => React.JSX.Element;
|
|
29
33
|
export default Profile;
|
|
@@ -28,6 +28,8 @@ const Profile = ({
|
|
|
28
28
|
email,
|
|
29
29
|
text,
|
|
30
30
|
darkBackground,
|
|
31
|
+
backgroundColor,
|
|
32
|
+
foregroundColor,
|
|
31
33
|
...props
|
|
32
34
|
}) => {
|
|
33
35
|
const getInitials = () => {
|
|
@@ -39,7 +41,10 @@ const Profile = ({
|
|
|
39
41
|
alt,
|
|
40
42
|
name,
|
|
41
43
|
initials: getInitials(),
|
|
42
|
-
size
|
|
44
|
+
size,
|
|
45
|
+
backgroundColor,
|
|
46
|
+
foregroundColor,
|
|
47
|
+
"data-role": "profile-portrait"
|
|
43
48
|
};
|
|
44
49
|
const avatar = () => {
|
|
45
50
|
if (src) {
|
|
@@ -10,5 +10,5 @@ declare const ProfileEmailStyle: import("styled-components").StyledComponent<imp
|
|
|
10
10
|
declare const ProfileTextStyle: import("styled-components").StyledComponent<"span", any, ProfileSProps, never>;
|
|
11
11
|
declare const ProfileStyle: import("styled-components").StyledComponent<"div", any, Pick<ProfileSProps, "darkBackground" | "hasSrc">, never>;
|
|
12
12
|
declare const ProfileDetailsStyle: import("styled-components").StyledComponent<"div", any, Pick<ProfileSProps, "size" | "hasSrc">, never>;
|
|
13
|
-
declare const ProfileAvatarStyle: import("styled-components").StyledComponent<({ alt, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: import("../portrait").PortraitProps) => import("react").JSX.Element, any, {}, never>;
|
|
13
|
+
declare const ProfileAvatarStyle: import("styled-components").StyledComponent<({ alt, backgroundColor, foregroundColor, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: import("../portrait").PortraitProps) => import("react").JSX.Element, any, {}, never>;
|
|
14
14
|
export { ProfileStyle, ProfileNameStyle, ProfileDetailsStyle, ProfileAvatarStyle, ProfileEmailStyle, ProfileTextStyle, };
|
|
@@ -203,8 +203,6 @@ const Switch = exports.Switch = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
203
203
|
width: labelInline ? "100%" : "auto"
|
|
204
204
|
}, /*#__PURE__*/_react.default.createElement(_box.default, {
|
|
205
205
|
"data-role": "label-wrapper"
|
|
206
|
-
// width={labelInline ? rest.labelWidth : 30}
|
|
207
|
-
// minWidth={label && labelInline ? "32px" : 0}
|
|
208
206
|
}, /*#__PURE__*/_react.default.createElement(_label.default, {
|
|
209
207
|
isDarkBackground: isDarkBackground,
|
|
210
208
|
labelId: labelId.current,
|
|
@@ -28,6 +28,10 @@ interface TimeInputProps extends Omit<TagProps, "data-component">, Omit<Validati
|
|
|
28
28
|
export interface TimeProps extends Omit<TagProps, "data-component">, MarginProps {
|
|
29
29
|
/** Label text for the component */
|
|
30
30
|
label?: string;
|
|
31
|
+
/** Label alignment */
|
|
32
|
+
labelAlign?: "left" | "right";
|
|
33
|
+
/** Field labels alignment */
|
|
34
|
+
fieldLabelsAlign?: "left" | "right";
|
|
31
35
|
/** Sets the size of the inputs */
|
|
32
36
|
size?: Sizes;
|
|
33
37
|
/** Additional hint text rendered above the input elements */
|
|
@@ -24,6 +24,8 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
24
24
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
25
25
|
const Time = /*#__PURE__*/_react.default.forwardRef(({
|
|
26
26
|
label,
|
|
27
|
+
labelAlign,
|
|
28
|
+
fieldLabelsAlign,
|
|
27
29
|
size = "medium",
|
|
28
30
|
inputHint,
|
|
29
31
|
hoursInputProps = {},
|
|
@@ -150,7 +152,8 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
150
152
|
legendMargin: {
|
|
151
153
|
mb: 0
|
|
152
154
|
},
|
|
153
|
-
width: "
|
|
155
|
+
width: "min-content",
|
|
156
|
+
legendAlign: labelAlign,
|
|
154
157
|
isRequired: required,
|
|
155
158
|
isOptional: isOptional,
|
|
156
159
|
isDisabled: disabled,
|
|
@@ -162,7 +165,8 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
162
165
|
id: inputHintId.current,
|
|
163
166
|
isDisabled: disabled
|
|
164
167
|
}, inputHint), /*#__PURE__*/_react.default.createElement(_box.default, {
|
|
165
|
-
position: "relative"
|
|
168
|
+
position: "relative",
|
|
169
|
+
mt: inputHint ? 0 : 1
|
|
166
170
|
}, /*#__PURE__*/_react.default.createElement(_validationMessage.default, {
|
|
167
171
|
validationId: validationId,
|
|
168
172
|
error: error,
|
|
@@ -174,7 +178,8 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
174
178
|
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_time.StyledLabel, {
|
|
175
179
|
"aria-label": hrsAriaLabel,
|
|
176
180
|
htmlFor: internalHrsId.current,
|
|
177
|
-
disabled: disabled
|
|
181
|
+
disabled: disabled,
|
|
182
|
+
align: fieldLabelsAlign
|
|
178
183
|
}, hrsLabel), /*#__PURE__*/_react.default.createElement(_number.default, _extends({}, hoursInputProps, {
|
|
179
184
|
label: undefined,
|
|
180
185
|
"data-component": "hours",
|
|
@@ -201,7 +206,8 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
201
206
|
}, ":")), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_time.StyledLabel, {
|
|
202
207
|
"aria-label": minsAriaLabel,
|
|
203
208
|
htmlFor: internalMinsId.current,
|
|
204
|
-
disabled: disabled
|
|
209
|
+
disabled: disabled,
|
|
210
|
+
align: fieldLabelsAlign
|
|
205
211
|
}, minsLabel), /*#__PURE__*/_react.default.createElement(_number.default, _extends({}, minutesInputProps, {
|
|
206
212
|
label: undefined,
|
|
207
213
|
"data-component": "minutes",
|
|
@@ -218,7 +224,8 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
218
224
|
}))), showToggle && /*#__PURE__*/_react.default.createElement(_box.default, {
|
|
219
225
|
display: "flex",
|
|
220
226
|
flexDirection: "column",
|
|
221
|
-
justifyContent: "flex-end"
|
|
227
|
+
justifyContent: "flex-end",
|
|
228
|
+
width: "max-content"
|
|
222
229
|
}, /*#__PURE__*/_react.default.createElement(_timeToggle.TimeToggle, {
|
|
223
230
|
toggleProps: toggleProps,
|
|
224
231
|
size: size,
|
|
@@ -233,6 +240,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
233
240
|
"data-element": _propTypes.default.string,
|
|
234
241
|
"data-role": _propTypes.default.string,
|
|
235
242
|
"disabled": _propTypes.default.bool,
|
|
243
|
+
"fieldLabelsAlign": _propTypes.default.oneOf(["left", "right"]),
|
|
236
244
|
"hoursInputProps": _propTypes.default.shape({
|
|
237
245
|
"aria-label": _propTypes.default.string,
|
|
238
246
|
"data-element": _propTypes.default.string,
|
|
@@ -245,6 +253,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
245
253
|
"inputHint": _propTypes.default.string,
|
|
246
254
|
"isOptional": _propTypes.default.bool,
|
|
247
255
|
"label": _propTypes.default.string,
|
|
256
|
+
"labelAlign": _propTypes.default.oneOf(["left", "right"]),
|
|
248
257
|
"m": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.number, _propTypes.default.shape({
|
|
249
258
|
"__@toStringTag": _propTypes.default.string.isRequired,
|
|
250
259
|
"description": _propTypes.default.string,
|
|
@@ -18,7 +18,7 @@ const StyledHintText = exports.StyledHintText = _styledComponents.default.div`
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
margin-top: var(--spacing000);
|
|
21
|
-
margin-bottom: var(--
|
|
21
|
+
margin-bottom: var(--spacing100);
|
|
22
22
|
color: ${({
|
|
23
23
|
isDisabled
|
|
24
24
|
}) => isDisabled ? "var(--colorsUtilityYin030)" : "var(--colorsUtilityYin055)"};
|