carbon-react 147.1.0 → 147.3.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/components/heading/heading.style.d.ts +1 -1
- package/esm/components/hr/hr.component.d.ts +3 -1
- package/esm/components/hr/hr.component.js +3 -0
- package/esm/components/hr/hr.style.d.ts +3 -1
- package/esm/components/hr/hr.style.js +8 -1
- 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/switch/switch.component.js +0 -2
- package/lib/components/heading/heading.style.d.ts +1 -1
- package/lib/components/hr/hr.component.d.ts +3 -1
- package/lib/components/hr/hr.component.js +3 -0
- package/lib/components/hr/hr.style.d.ts +3 -1
- package/lib/components/hr/hr.style.js +8 -1
- 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/switch/switch.component.js +0 -2
- package/package.json +1 -1
|
@@ -23,7 +23,7 @@ declare type StyledSubHeaderProps = {
|
|
|
23
23
|
declare const StyledSubHeader: import("styled-components").StyledComponent<"div", any, StyledSubHeaderProps, never>;
|
|
24
24
|
declare const StyledHeadingIcon: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../icon").IconProps & import("react").RefAttributes<HTMLSpanElement>>, any, {}, never>;
|
|
25
25
|
declare const StyledSeparator: import("styled-components").StyledComponent<"hr", any, {}, never>;
|
|
26
|
-
declare const StyledDivider: import("styled-components").StyledComponent<({ adaptiveMxBreakpoint, ml, mr, "aria-hidden": ariaHidden, ...rest }: import("../hr").HrProps) => JSX.Element, any, {}, never>;
|
|
26
|
+
declare const StyledDivider: import("styled-components").StyledComponent<({ adaptiveMxBreakpoint, ml, mr, "aria-hidden": ariaHidden, height, ...rest }: import("../hr").HrProps) => JSX.Element, any, {}, never>;
|
|
27
27
|
declare const StyledHeaderHelp: import("styled-components").StyledComponent<{
|
|
28
28
|
({ as, ariaLabel, children, href, helpId, isFocused, tabIndex, tooltipBgColor, tooltipFontColor, tooltipFlipOverrides, tooltipId, tooltipPosition, type, ...rest }: import("../help").HelpProps): JSX.Element;
|
|
29
29
|
displayName: string;
|
|
@@ -6,6 +6,8 @@ export interface HrProps extends MarginProps {
|
|
|
6
6
|
/** Breakpoint for adaptive left and right margins (below the breakpoint they go to 0).
|
|
7
7
|
* Enables the adaptive behaviour when set */
|
|
8
8
|
adaptiveMxBreakpoint?: number;
|
|
9
|
+
/** Set the height of the component. Accepts one of "small", "medium", or "large" */
|
|
10
|
+
height?: "small" | "medium" | "large";
|
|
9
11
|
}
|
|
10
|
-
export declare const Hr: ({ adaptiveMxBreakpoint, ml, mr, "aria-hidden": ariaHidden, ...rest }: HrProps) => JSX.Element;
|
|
12
|
+
export declare const Hr: ({ adaptiveMxBreakpoint, ml, mr, "aria-hidden": ariaHidden, height, ...rest }: HrProps) => JSX.Element;
|
|
11
13
|
export default Hr;
|
|
@@ -8,6 +8,7 @@ const Hr = ({
|
|
|
8
8
|
ml,
|
|
9
9
|
mr,
|
|
10
10
|
"aria-hidden": ariaHidden,
|
|
11
|
+
height = "small",
|
|
11
12
|
...rest
|
|
12
13
|
}) => {
|
|
13
14
|
const largeScreen = useIsAboveBreakpoint(adaptiveMxBreakpoint);
|
|
@@ -21,6 +22,7 @@ const Hr = ({
|
|
|
21
22
|
"aria-hidden": ariaHidden,
|
|
22
23
|
"data-component": "hr",
|
|
23
24
|
"data-role": "hr",
|
|
25
|
+
height: height,
|
|
24
26
|
ml: marginLeft,
|
|
25
27
|
mr: marginRight,
|
|
26
28
|
mt: rest.mt || 3,
|
|
@@ -31,6 +33,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
31
33
|
Hr.propTypes = {
|
|
32
34
|
"adaptiveMxBreakpoint": PropTypes.number,
|
|
33
35
|
"aria-hidden": PropTypes.oneOf(["false", "true"]),
|
|
36
|
+
"height": PropTypes.oneOf(["large", "medium", "small"]),
|
|
34
37
|
"m": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
|
|
35
38
|
"__@toStringTag": PropTypes.string.isRequired,
|
|
36
39
|
"description": PropTypes.string,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { MarginProps } from "styled-system";
|
|
2
|
-
declare const StyledHr: import("styled-components").StyledComponent<"hr", any, MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem
|
|
2
|
+
declare const StyledHr: import("styled-components").StyledComponent<"hr", any, MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
|
|
3
|
+
height: "small" | "medium" | "large";
|
|
4
|
+
}, never>;
|
|
3
5
|
export default StyledHr;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import styled from "styled-components";
|
|
2
2
|
import { margin } from "styled-system";
|
|
3
3
|
import baseTheme from "../../style/themes/base";
|
|
4
|
+
const heightMap = {
|
|
5
|
+
small: 1,
|
|
6
|
+
medium: 2,
|
|
7
|
+
large: 3
|
|
8
|
+
};
|
|
4
9
|
const StyledHr = styled.hr`
|
|
5
10
|
${margin}
|
|
6
11
|
width: inherit;
|
|
7
12
|
border: 0;
|
|
8
|
-
height:
|
|
13
|
+
height: ${({
|
|
14
|
+
height
|
|
15
|
+
}) => heightMap[height]}px;
|
|
9
16
|
background: var(--colorsUtilityMajor100);
|
|
10
17
|
`;
|
|
11
18
|
StyledHr.defaultProps = {
|
|
@@ -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,
|
|
@@ -23,7 +23,7 @@ declare type StyledSubHeaderProps = {
|
|
|
23
23
|
declare const StyledSubHeader: import("styled-components").StyledComponent<"div", any, StyledSubHeaderProps, never>;
|
|
24
24
|
declare const StyledHeadingIcon: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../icon").IconProps & import("react").RefAttributes<HTMLSpanElement>>, any, {}, never>;
|
|
25
25
|
declare const StyledSeparator: import("styled-components").StyledComponent<"hr", any, {}, never>;
|
|
26
|
-
declare const StyledDivider: import("styled-components").StyledComponent<({ adaptiveMxBreakpoint, ml, mr, "aria-hidden": ariaHidden, ...rest }: import("../hr").HrProps) => JSX.Element, any, {}, never>;
|
|
26
|
+
declare const StyledDivider: import("styled-components").StyledComponent<({ adaptiveMxBreakpoint, ml, mr, "aria-hidden": ariaHidden, height, ...rest }: import("../hr").HrProps) => JSX.Element, any, {}, never>;
|
|
27
27
|
declare const StyledHeaderHelp: import("styled-components").StyledComponent<{
|
|
28
28
|
({ as, ariaLabel, children, href, helpId, isFocused, tabIndex, tooltipBgColor, tooltipFontColor, tooltipFlipOverrides, tooltipId, tooltipPosition, type, ...rest }: import("../help").HelpProps): JSX.Element;
|
|
29
29
|
displayName: string;
|
|
@@ -6,6 +6,8 @@ export interface HrProps extends MarginProps {
|
|
|
6
6
|
/** Breakpoint for adaptive left and right margins (below the breakpoint they go to 0).
|
|
7
7
|
* Enables the adaptive behaviour when set */
|
|
8
8
|
adaptiveMxBreakpoint?: number;
|
|
9
|
+
/** Set the height of the component. Accepts one of "small", "medium", or "large" */
|
|
10
|
+
height?: "small" | "medium" | "large";
|
|
9
11
|
}
|
|
10
|
-
export declare const Hr: ({ adaptiveMxBreakpoint, ml, mr, "aria-hidden": ariaHidden, ...rest }: HrProps) => JSX.Element;
|
|
12
|
+
export declare const Hr: ({ adaptiveMxBreakpoint, ml, mr, "aria-hidden": ariaHidden, height, ...rest }: HrProps) => JSX.Element;
|
|
11
13
|
export default Hr;
|
|
@@ -15,6 +15,7 @@ const Hr = ({
|
|
|
15
15
|
ml,
|
|
16
16
|
mr,
|
|
17
17
|
"aria-hidden": ariaHidden,
|
|
18
|
+
height = "small",
|
|
18
19
|
...rest
|
|
19
20
|
}) => {
|
|
20
21
|
const largeScreen = (0, _useIsAboveBreakpoint.default)(adaptiveMxBreakpoint);
|
|
@@ -28,6 +29,7 @@ const Hr = ({
|
|
|
28
29
|
"aria-hidden": ariaHidden,
|
|
29
30
|
"data-component": "hr",
|
|
30
31
|
"data-role": "hr",
|
|
32
|
+
height: height,
|
|
31
33
|
ml: marginLeft,
|
|
32
34
|
mr: marginRight,
|
|
33
35
|
mt: rest.mt || 3,
|
|
@@ -39,6 +41,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
39
41
|
Hr.propTypes = {
|
|
40
42
|
"adaptiveMxBreakpoint": _propTypes.default.number,
|
|
41
43
|
"aria-hidden": _propTypes.default.oneOf(["false", "true"]),
|
|
44
|
+
"height": _propTypes.default.oneOf(["large", "medium", "small"]),
|
|
42
45
|
"m": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.number, _propTypes.default.shape({
|
|
43
46
|
"__@toStringTag": _propTypes.default.string.isRequired,
|
|
44
47
|
"description": _propTypes.default.string,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { MarginProps } from "styled-system";
|
|
2
|
-
declare const StyledHr: import("styled-components").StyledComponent<"hr", any, MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem
|
|
2
|
+
declare const StyledHr: import("styled-components").StyledComponent<"hr", any, MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
|
|
3
|
+
height: "small" | "medium" | "large";
|
|
4
|
+
}, never>;
|
|
3
5
|
export default StyledHr;
|
|
@@ -8,11 +8,18 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
|
8
8
|
var _styledSystem = require("styled-system");
|
|
9
9
|
var _base = _interopRequireDefault(require("../../style/themes/base"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const heightMap = {
|
|
12
|
+
small: 1,
|
|
13
|
+
medium: 2,
|
|
14
|
+
large: 3
|
|
15
|
+
};
|
|
11
16
|
const StyledHr = _styledComponents.default.hr`
|
|
12
17
|
${_styledSystem.margin}
|
|
13
18
|
width: inherit;
|
|
14
19
|
border: 0;
|
|
15
|
-
height:
|
|
20
|
+
height: ${({
|
|
21
|
+
height
|
|
22
|
+
}) => heightMap[height]}px;
|
|
16
23
|
background: var(--colorsUtilityMajor100);
|
|
17
24
|
`;
|
|
18
25
|
StyledHr.defaultProps = {
|
|
@@ -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,
|