@thecb/components 4.4.4 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "4.4.4",
3
+ "version": "4.5.1",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -0,0 +1,78 @@
1
+ import React from "react";
2
+ import { FONT_WEIGHT_REGULAR } from "../../../constants/style_constants";
3
+ import { FIREFLY_GREY } from "../../../constants/colors";
4
+ import { DetailText } from "./Detail.styled";
5
+ import { safeChildren } from "../../../util/general";
6
+ import {
7
+ fallbackValues,
8
+ mobileFallbackValues,
9
+ MOBILE_BREAKPOINT
10
+ } from "./Detail.theme";
11
+ import { themeComponent } from "../../../util/themeUtils";
12
+
13
+ /*
14
+ New responsive text component for Detail elements
15
+ (Block level text elements which are smaller than "Title" elements)
16
+ Size is decoupled from tag
17
+ Comes with four variants - "large", "regular", "small", "extraSmall"
18
+ Large variant results in text that is 1.125rem/1.1428rem (18px desktop, 16px mobile)
19
+ Regular variant results in text that is 1rem (16px desktop, 14px mobile)
20
+ Small variant reuslts in text that is 0.875rem/0.8571rem (14px desktop, 12px mobile)
21
+ ExtraSmall variant results in text that is 0.75rem/0.7142rem (12px desktop, 10px mobile)
22
+
23
+ If you need a larger font size, use the <Title /> atom, which has larger variants
24
+
25
+ Use the "as" prop to specify element type, can use any of: h1/h2/h3/h4/h5/h6/p
26
+ If you need an inline text element (span), use the <Text /> atom
27
+ The "as" value should be dictated by the structure of your page, not what font-size you want
28
+
29
+ Title / Detail both use slightly different desktop/mobile scales
30
+ (Mobile scale is different to allow for design-friendly px values)
31
+ Both atoms detect the presence of a mobile device on their own
32
+ and apply the corresponding scale
33
+
34
+ Mobile breakpoint value is specified in Detail.theme.js
35
+
36
+ If you want to disable mobile text scales (use the same rem scale for desktop/mobile), then use a theme in FCS to set all of the variants to use the same rem sizes. FCS themes override fallbacks defined in the .theme file
37
+ */
38
+
39
+ const isBelowBreakpoint = window.innerWidth < MOBILE_BREAKPOINT;
40
+ const isTouchDevice = "ontouchstart" in window || navigator.maxTouchPoints > 1;
41
+ const mobileDeviceDetected = isBelowBreakpoint && isTouchDevice;
42
+ const fallbacks = mobileDeviceDetected ? mobileFallbackValues : fallbackValues;
43
+
44
+ const Detail = ({
45
+ themeValues,
46
+ weight = FONT_WEIGHT_REGULAR,
47
+ color = FIREFLY_GREY,
48
+ margin = 0,
49
+ textAlign,
50
+ extraStyles = ``,
51
+ className,
52
+ variant = "regular",
53
+ as = "p",
54
+ dataQa,
55
+ children,
56
+ ...rest
57
+ }) => {
58
+ return (
59
+ <DetailText
60
+ variant={variant}
61
+ as={as}
62
+ weight={weight}
63
+ color={color}
64
+ margin={margin}
65
+ textAlign={textAlign}
66
+ extraStyles={extraStyles}
67
+ className={className}
68
+ fontFamily={themeValues.fontFamily}
69
+ fontSize={themeValues.fontSize}
70
+ data-qa={dataQa}
71
+ {...rest}
72
+ >
73
+ {safeChildren(children, <span />)}
74
+ </DetailText>
75
+ );
76
+ };
77
+
78
+ export default themeComponent(Detail, "Detail", fallbacks, "regular");
@@ -0,0 +1,13 @@
1
+ import styled from "styled-components";
2
+
3
+ export const DetailText = styled.p`
4
+ font-size: ${({ fontSize }) => fontSize};
5
+ line-height: 1.5;
6
+ color: ${({ color }) => color};
7
+ font-weight: ${({ weight }) => weight};
8
+ margin: ${({ margin }) => margin};
9
+ text-align: ${({ textAlign }) => textAlign};
10
+ font-family: ${({ fontFamily }) => fontFamily};
11
+
12
+ ${({ extraStyles }) => extraStyles};
13
+ `;
@@ -0,0 +1,32 @@
1
+ const fontSize = {
2
+ large: "1.125rem",
3
+ regular: "1rem",
4
+ small: "0.875rem",
5
+ extraSmall: "0.75rem"
6
+ };
7
+
8
+ const fontFamily = {
9
+ large: "Public Sans",
10
+ regular: "Public Sans",
11
+ small: "Public Sans",
12
+ extraSmall: "Public Sans"
13
+ };
14
+
15
+ const mobileFontSize = {
16
+ large: "1.14285rem",
17
+ regular: "1",
18
+ small: "0.85714rem",
19
+ extraSmall: "0.71428rem"
20
+ };
21
+
22
+ export const fallbackValues = {
23
+ fontFamily,
24
+ fontSize
25
+ };
26
+
27
+ export const mobileFallbackValues = {
28
+ fontFamily,
29
+ fontSize: mobileFontSize
30
+ };
31
+
32
+ export const MOBILE_BREAKPOINT = 768;
@@ -0,0 +1,3 @@
1
+ import Detail from "./Detail";
2
+
3
+ export default Detail;
@@ -1,3 +1,9 @@
1
+ /*
2
+ SOON TO BE DEPRECATED AS OF 8/1/2021
3
+
4
+ For new pages/applications, please us <Title /> and <Detail /> atoms
5
+
6
+ */
1
7
  import React from "react";
2
8
  import { FONT_WEIGHT_REGULAR } from "../../../constants/style_constants";
3
9
  import { FIREFLY_GREY } from "../../../constants/colors";
@@ -9,6 +9,7 @@ export { default as cardRegistry } from "./card";
9
9
  export { default as Checkbox } from "./checkbox";
10
10
  export { default as CheckboxList } from "./checkbox-list";
11
11
  export { default as CountryDropdown } from "./country-dropdown";
12
+ export { default as Detail } from "./detail";
12
13
  export { default as DisplayBox } from "./display-box";
13
14
  export { default as DisplayCard } from "./display-card";
14
15
  export { default as Dropdown } from "./dropdown";
@@ -37,5 +38,6 @@ export { default as SolidDivider } from "./solid-divider";
37
38
  export { default as Spinner } from "./spinner";
38
39
  export { default as StateProvinceDropdown } from "./state-province-dropdown";
39
40
  export { default as Text } from "./text";
41
+ export { default as Title } from "./title";
40
42
  export { default as ToggleSwitch } from "./toggle-switch";
41
43
  export { default as TypeaheadInput } from "./typeahead-input";
@@ -1,3 +1,9 @@
1
+ /*
2
+ SOON TO BE DEPRECATED AS OF 8/1/2021
3
+
4
+ For new pages/applications, please us <Title /> and <Detail /> atoms
5
+
6
+ */
1
7
  import React from "react";
2
8
  import { fallbackValues } from "./Paragraph.theme";
3
9
  import { themeComponent } from "../../../util/themeUtils";
@@ -0,0 +1,75 @@
1
+ import React from "react";
2
+ import { FONT_WEIGHT_REGULAR } from "../../../constants/style_constants";
3
+ import { FIREFLY_GREY } from "../../../constants/colors";
4
+ import { TitleText } from "./Title.styled";
5
+ import { safeChildren } from "../../../util/general";
6
+ import {
7
+ fallbackValues,
8
+ mobileFallbackValues,
9
+ MOBILE_BREAKPOINT
10
+ } from "./Title.theme";
11
+ import { themeComponent } from "../../../util/themeUtils";
12
+
13
+ /*
14
+ New responsive text component for Title elements
15
+ Size is decoupled from tag
16
+ Comes with two variants - "large" and "small"
17
+ Large variant results in text that is 1.5rem (24px desktop, 21px mobile)
18
+ Small variant results in text that is 1.25rem/1.2142rem (20px desktop, 17px mobile)
19
+
20
+ If you need a smaller text size, use the <Detail /> atom, which has smaller variants
21
+
22
+ Use the "as" prop to specify element type, can use any of: h1/h2/h3/h4/h5/h6/p
23
+ If you need an inline text element (span), use the <Text /> atom
24
+ The "as" value should be dictated by the structure of your page, not what font-size you want
25
+
26
+ Title / Detail both use slightly different desktop/mobile scales
27
+ (Mobile scale is different to allow for design-friendly px values)
28
+ Both atoms detect the presence of a mobile device on their own
29
+ and apply the corresponding scale
30
+
31
+ Mobile breakpoint value is specified in Title.theme.js
32
+
33
+ If you want to disable mobile text scales (use the same rem scale for desktop/mobile), then use a theme in FCS to set both the "large" and "small" variants to use the same rem sizes. FCS themes override fallbacks defined in the .theme file
34
+ */
35
+
36
+ const isBelowBreakpoint = window.innerWidth < MOBILE_BREAKPOINT;
37
+ const isTouchDevice = "ontouchstart" in window || navigator.maxTouchPoints > 1;
38
+ const mobileDeviceDetected = isBelowBreakpoint && isTouchDevice;
39
+ const fallbacks = mobileDeviceDetected ? mobileFallbackValues : fallbackValues;
40
+
41
+ const Title = ({
42
+ themeValues,
43
+ weight = FONT_WEIGHT_REGULAR,
44
+ color = FIREFLY_GREY,
45
+ margin = 0,
46
+ textAlign,
47
+ extraStyles = ``,
48
+ className,
49
+ variant = "large",
50
+ as = "h1",
51
+ dataQa,
52
+ children,
53
+ ...rest
54
+ }) => {
55
+ return (
56
+ <TitleText
57
+ variant={variant}
58
+ as={as}
59
+ weight={weight}
60
+ color={color}
61
+ margin={margin}
62
+ textAlign={textAlign}
63
+ extraStyles={extraStyles}
64
+ className={className}
65
+ fontFamily={themeValues.fontFamily}
66
+ fontSize={themeValues.fontSize}
67
+ data-qa={dataQa}
68
+ {...rest}
69
+ >
70
+ {safeChildren(children, <span />)}
71
+ </TitleText>
72
+ );
73
+ };
74
+
75
+ export default themeComponent(Title, "Title", fallbacks, "large");
@@ -0,0 +1,13 @@
1
+ import styled from "styled-components";
2
+
3
+ export const TitleText = styled.h1`
4
+ font-size: ${({ fontSize }) => fontSize};
5
+ line-height: 1.5;
6
+ color: ${({ color }) => color};
7
+ font-weight: ${({ weight }) => weight};
8
+ margin: ${({ margin }) => margin};
9
+ text-align: ${({ textAlign }) => textAlign};
10
+ font-family: ${({ fontFamily }) => fontFamily};
11
+
12
+ ${({ extraStyles }) => extraStyles};
13
+ `;
@@ -0,0 +1,26 @@
1
+ const fontSize = {
2
+ large: "1.5rem",
3
+ small: "1.25rem"
4
+ };
5
+
6
+ const fontFamily = {
7
+ large: "Public Sans",
8
+ small: "Public Sans"
9
+ };
10
+
11
+ const mobileFontSize = {
12
+ large: "1.5rem",
13
+ small: "1.2142rem"
14
+ };
15
+
16
+ export const fallbackValues = {
17
+ fontFamily,
18
+ fontSize
19
+ };
20
+
21
+ export const mobileFallbackValues = {
22
+ fontFamily,
23
+ fontSize: mobileFontSize
24
+ };
25
+
26
+ export const MOBILE_BREAKPOINT = 768;
@@ -0,0 +1,3 @@
1
+ import Title from "./Title";
2
+
3
+ export default Title;
@@ -33,7 +33,7 @@ const PaymentDetailsContent = ({
33
33
  </Box>
34
34
  <SolidDivider />
35
35
  <LabeledAmount
36
- as="h2"
36
+ as="p"
37
37
  variant={themeValues.labeledAmountTotal}
38
38
  label="Total"
39
39
  amount={displayCurrency(total)}