@thecb/components 12.0.1-beta.1 → 12.0.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": "12.0.1-beta.1",
3
+ "version": "12.0.1",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -101,6 +101,7 @@ const Checkbox = forwardRef(
101
101
  themeValues,
102
102
  hidden = false,
103
103
  error = false,
104
+ isRequired = false,
104
105
  checkboxMargin = "0 16px 0 0",
105
106
  extraStyles,
106
107
  textExtraStyles,
@@ -130,6 +131,13 @@ const Checkbox = forwardRef(
130
131
  ref={ref}
131
132
  padding="0"
132
133
  tabIndex="0"
134
+ role="checkbox"
135
+ aria-checked={checked}
136
+ aria-required={isRequired || undefined}
137
+ aria-invalid={error}
138
+ aria-label={ariaLabel}
139
+ aria-labelledby={ariaLabelledById}
140
+ aria-describedby={error ? `${name}-error-message` : undefined}
133
141
  onFocus={() => setFocused(true)}
134
142
  onBlur={() => setFocused(false)}
135
143
  onKeyDown={e => handleClick(e, onChange)}
@@ -150,20 +158,17 @@ const Checkbox = forwardRef(
150
158
  id={`checkbox-${name}`}
151
159
  disabled={disabled}
152
160
  name={name}
153
- aria-label={ariaLabel}
154
- aria-labelledby={ariaLabelledById}
155
161
  checked={checked}
156
162
  onChange={onChange}
157
163
  tabIndex="-1"
158
- aria-invalid={error}
159
- aria-describedby={error ? `${name}-error-message` : ""}
164
+ required={isRequired}
165
+ aria-hidden="true"
160
166
  />
161
167
  <StyledCheckbox
162
- role="checkbox"
168
+ aria-hidden="true"
163
169
  error={error}
164
170
  disabled={disabled}
165
171
  checked={checked}
166
- aria-checked={checked}
167
172
  focused={focused}
168
173
  defaultStyles={themeValues.defaultStyles}
169
174
  checkedStyles={themeValues.checkedStyles}
@@ -224,6 +224,7 @@ const FormInput = ({
224
224
  (field.dirty && field.hasErrors) ||
225
225
  (field.hasErrors && showErrors)
226
226
  }
227
+ aria-required={isRequired}
227
228
  onChange={value => setValue(value)}
228
229
  onBlur={e => handleOnBlur(e.target.value)}
229
230
  type={type}
@@ -265,6 +266,7 @@ const FormInput = ({
265
266
  (field.dirty && field.hasErrors) ||
266
267
  (field.hasErrors && showErrors)
267
268
  }
269
+ aria-required={isRequired}
268
270
  onChange={e => setValue(e.target.value)}
269
271
  onBlur={e => handleOnBlur(e.target.value)}
270
272
  type={type === "password" && showPassword ? "text" : type}
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
2
  import { Box, Stack } from "../../atoms/layouts";
3
- import { ExternalLink, InternalLink } from "../../atoms/link";
4
3
  import { themeComponent } from "../../../util/themeUtils";
5
4
  import { fallbackValues } from "./LinkCard.theme";
6
5
  import * as Styled from "./LinkCard.styled";
@@ -26,102 +25,79 @@ const LinkCard = ({
26
25
  const regex = /\W/g;
27
26
  const locatorSlug = title?.toLowerCase?.()?.replaceAll?.(regex, "-");
28
27
 
29
- const baseStyles = Styled.getCardBaseStyles(
30
- themeValues,
31
- disabled,
32
- extraStyles
33
- );
34
- const hoverActiveStyles = Styled.getCardHoverActiveStyles(
35
- themeValues,
36
- disabled,
37
- extraHoverStyles,
38
- extraActiveStyles
39
- );
40
-
41
- const cardContent = (
42
- <Stack
43
- childGap={0}
44
- bottomItem={3}
45
- justify="space-between"
46
- style={{ width: "100%" }}
47
- fullHeight
48
- >
49
- <Stack
50
- direction="row"
51
- childGap="0.5rem"
52
- extraStyles={`align-items: center;`}
53
- >
54
- <Styled.Title
55
- variant={titleVariant}
56
- $theme={themeValues}
57
- margin={0}
58
- $disabled={disabled}
59
- >
60
- {title}
61
- </Styled.Title>
62
- {isExternalLink && (
63
- <ExternalLinkIcon
64
- linkColor={themeValues.color}
65
- text={locatorSlug}
66
- style={{ height: "1.125rem", width: "1.125rem" }}
67
- />
68
- )}
69
- </Stack>
70
- <Box padding={subtitlePadding} width="100%">
71
- <Styled.Subtitle variant="pS" $theme={themeValues} $disabled={disabled}>
72
- {subtitle}
73
- </Styled.Subtitle>
74
- </Box>
75
- <Box
76
- background="transparent"
77
- borderWidthOverride="0 0 0 0"
78
- padding="0"
79
- width="100%"
80
- >
81
- <Styled.Footer direction="row" childGap="6px" justify="space-between">
82
- {/* To keep rightContent aligned right, use an empty Box as leftContent if none is provided */}
83
- {showLeft && !!leftContent ? (
84
- leftContent
85
- ) : (
86
- <Box extraStyles="margin-right: auto;" />
87
- )}
88
- {showRight && !!rightContent && rightContent}
89
- </Styled.Footer>
90
- </Box>
91
- </Stack>
92
- );
93
-
94
- if (isExternalLink) {
95
- return (
96
- <ExternalLink
97
- key={`link-card-${locatorSlug}`}
98
- href={disabled ? "" : href}
99
- newTab={true}
100
- isUnderlined={false}
101
- tabIndex={disabled ? "-1" : "0"}
102
- ariaLabel={`${title}, ${subtitle}`}
103
- dataQa={`link-card-${locatorSlug}`}
104
- extraStyles={`${baseStyles} ${hoverActiveStyles}`}
105
- >
106
- {cardContent}
107
- </ExternalLink>
108
- );
109
- }
110
-
111
28
  return (
112
- <InternalLink
29
+ <Styled.StyledAnchor
113
30
  key={`link-card-${locatorSlug}`}
114
- to={disabled ? "" : href}
115
- isUnderlined={false}
116
- hoverUnderline={false}
117
- tabIndex={disabled ? "-1" : "0"}
118
- aria-label={`${title}, ${subtitle}`}
31
+ href={disabled ? undefined : href}
32
+ rel={isExternalLink ? "noopener noreferrer" : undefined}
33
+ target={isExternalLink ? "_blank" : undefined}
34
+ tabIndex={disabled ? -1 : 0}
119
35
  aria-disabled={disabled}
36
+ $disabled={disabled}
37
+ aria-label={`${title}, ${subtitle}`}
120
38
  data-qa={`link-card-${locatorSlug}`}
121
- extraStyles={`${baseStyles} ${hoverActiveStyles}`}
39
+ $theme={themeValues}
40
+ $extraStyles={
41
+ disabled ? `pointer-events: none; ${extraStyles}` : extraStyles
42
+ }
43
+ $hoverStyles={extraHoverStyles}
44
+ $activeStyles={extraActiveStyles}
122
45
  >
123
- {cardContent}
124
- </InternalLink>
46
+ <Stack
47
+ childGap={0}
48
+ bottomItem={3}
49
+ justify="space-between"
50
+ style={{ width: "100%" }}
51
+ fullHeight
52
+ >
53
+ <Stack
54
+ direction="row"
55
+ childGap="0.5rem"
56
+ extraStyles={`align-items: center;`}
57
+ >
58
+ <Styled.Title
59
+ variant={titleVariant}
60
+ $theme={themeValues}
61
+ margin={0}
62
+ $disabled={disabled}
63
+ >
64
+ {title}
65
+ </Styled.Title>
66
+ {isExternalLink && (
67
+ <ExternalLinkIcon
68
+ linkColor={themeValues.color}
69
+ text={locatorSlug}
70
+ style={{ height: "1.125rem", width: "1.125rem" }}
71
+ />
72
+ )}
73
+ </Stack>
74
+ <Box padding={subtitlePadding} width="100%">
75
+ <Styled.Subtitle
76
+ variant="pS"
77
+ $theme={themeValues}
78
+ $disabled={disabled}
79
+ >
80
+ {subtitle}
81
+ </Styled.Subtitle>
82
+ </Box>
83
+ <Box
84
+ background="transparent"
85
+ borderWidthOverride="0 0 0 0"
86
+ padding="0"
87
+ width="100%"
88
+ >
89
+ <Styled.Footer direction="row" childGap="6px" justify="space-between">
90
+ {/* To keep rightContent aligned right, use an empty Box as leftContent if none is provided */}
91
+ {showLeft && !!leftContent ? (
92
+ leftContent
93
+ ) : (
94
+ <Box extraStyles="margin-right: auto;" />
95
+ )}
96
+ {showRight && !!rightContent && rightContent}
97
+ </Styled.Footer>
98
+ </Box>
99
+ </Stack>
100
+ </Styled.StyledAnchor>
125
101
  );
126
102
  };
127
103
 
@@ -8,6 +8,7 @@ import {
8
8
  import { Box } from "../../atoms/layouts";
9
9
  import LinkCard from "./LinkCard";
10
10
  import Badge from "../../atoms/badge/Badge";
11
+ import { fn } from "@storybook/test";
11
12
  import AutopayIcon from "../../atoms/icons/AutopayIcon";
12
13
  import ArrowRightIcon from "../../atoms/icons/ArrowRightIcon";
13
14
  import PlusCircleIcon from "../../atoms/icons/PlusCircleIcon";
@@ -23,11 +24,11 @@ const meta = {
23
24
  args: {
24
25
  title: "Test Workflow",
25
26
  subtitle: "Link your benefit plan",
26
- href: "/test-workflow",
27
27
  showLeft: undefined,
28
28
  leftContent: undefined,
29
29
  showRight: undefined,
30
30
  rightContent: undefined,
31
+ onClick: fn(),
31
32
  extraStyles: "",
32
33
  extraActiveStyles: "",
33
34
  extraHoverStyles: "",
@@ -50,14 +51,6 @@ const meta = {
50
51
  defaultValue: { summary: "Link your benefit plan" }
51
52
  }
52
53
  },
53
- href: {
54
- description:
55
- "URL or path for the LinkCard. Internal path for InternalLink, full URL for ExternalLink",
56
- table: {
57
- type: { summary: "string" },
58
- defaultValue: { summary: undefined }
59
- }
60
- },
61
54
  showLeft: {
62
55
  description: "Whether to show the LinkCard's left content",
63
56
  table: {
@@ -86,6 +79,13 @@ const meta = {
86
79
  defaultValue: { summary: undefined }
87
80
  }
88
81
  },
82
+ onClick: {
83
+ description: "Function to execute on click of LinkCard",
84
+ table: {
85
+ type: { summary: "function" },
86
+ defaultValue: { summary: undefined }
87
+ }
88
+ },
89
89
  extraStyles: {
90
90
  description: "Extra styles to apply to the LinkCard",
91
91
  table: {
@@ -139,8 +139,7 @@ export default meta;
139
139
  export const BasicLinkCard = {
140
140
  args: {
141
141
  title: "Construction Permits",
142
- subtitle: "Cityville Department of Building Inspection",
143
- href: "/permits/construction"
142
+ subtitle: "Cityville Department of Building Inspection"
144
143
  },
145
144
  render: args => {
146
145
  return (
@@ -197,8 +196,7 @@ export const BasicLinkCard = {
197
196
  export const ExternalLinkCard = {
198
197
  args: {
199
198
  title: "Construction Permits",
200
- subtitle: "Cityville Department of Building Inspection",
201
- href: "https://example.com/permits/construction"
199
+ subtitle: "Cityville Department of Building Inspection"
202
200
  },
203
201
  render: args => {
204
202
  return (
@@ -256,8 +254,7 @@ export const ExternalLinkCard = {
256
254
  export const CompleteLinkCard = {
257
255
  args: {
258
256
  title: "Water Bills - Autopay",
259
- subittle: "Cityville Water Management",
260
- href: "/water-bills/autopay"
257
+ subittle: "Cityville Water Management"
261
258
  },
262
259
  render: args => {
263
260
  return (
@@ -315,8 +312,7 @@ export const CompleteLinkCard = {
315
312
  export const DisabledLinkCard = {
316
313
  args: {
317
314
  title: "Property Tax - Autopay",
318
- subtitle: "",
319
- href: "/property-tax/autopay"
315
+ subtitle: ""
320
316
  },
321
317
  render: args => {
322
318
  return (
@@ -7,7 +7,16 @@ import {
7
7
  FONT_WEIGHT_REGULAR
8
8
  } from "../../../constants/style_constants";
9
9
 
10
- export const getCardBaseStyles = (theme, disabled, extraStyles) => `
10
+ export const StyledAnchor = styled("a")`
11
+ ${({
12
+ $disabled: disabled,
13
+ $theme: theme,
14
+ $extraStyles: extraStyles,
15
+ $disabledStyles: disabledStyles,
16
+ $hoverStyles: hoverStyles,
17
+ $activeStyles: activeStyles
18
+ }) => `
19
+ display: flex;
11
20
  flex-direction: column;
12
21
  align-items: flex-start;
13
22
  gap: 40px;
@@ -16,60 +25,51 @@ export const getCardBaseStyles = (theme, disabled, extraStyles) => `
16
25
  align-self: stretch;
17
26
  border-radius: 8px;
18
27
  text-decoration: none;
19
- font-size: inherit;
20
- color: inherit;
21
- font-weight: inherit;
22
- line-height: inherit;
23
28
  background-color: ${
24
29
  disabled ? theme.disabledBackgroundColor : theme.backgroundColor
25
30
  };
26
31
  border: 1px solid
27
32
  ${disabled ? theme.disabledBorderColor : theme.borderColor};
28
33
  transition: all 0.2s ease-in-out;
29
- ${disabled ? `pointer-events: none;` : ""}
30
34
  ${extraStyles || ""}
31
- `;
32
35
 
33
- export const getCardHoverActiveStyles = (
34
- theme,
35
- disabled,
36
- hoverStyles,
37
- activeStyles
38
- ) => {
39
- if (disabled) {
40
- return `
41
- &:hover,
42
- &:active {
43
- cursor: default;
44
- box-shadow: none;
45
- border: 1px solid ${theme.disabledBorderColor};
46
- }
47
- `;
48
- }
49
- return `
50
- &:hover,
51
- &:active {
52
- cursor: pointer;
53
- box-shadow: 0px 0px 0px 0px rgba(41, 42, 51, 0.1),
54
- 0px 5px 11px 0px rgba(41, 42, 51, 0.1),
55
- 0px 4px 19px 0px rgba(41, 42, 51, 0.09),
56
- 0px 27px 26px 0px rgba(41, 42, 51, 0.05),
57
- 0px 56px 31px 0px rgba(41, 42, 51, 0.01),
58
- 0px 80px 33px 0px rgba(41, 42, 51, 0);
59
- }
60
- ${hoverStyles || ""}
36
+ ${
37
+ disabled
38
+ ? `
39
+ &:hover,
40
+ &:active {
41
+ cursor: default;
42
+ box-shadow: none;
43
+ border: 1px solid ${theme.disabledBorderColor};
44
+ ${disabledStyles || ""}
45
+ }
46
+ `
47
+ : `
48
+ &:hover,
49
+ &:active {
50
+ cursor: pointer;
51
+ box-shadow: 0px 0px 0px 0px rgba(41, 42, 51, 0.1),
52
+ 0px 5px 11px 0px rgba(41, 42, 51, 0.1),
53
+ 0px 4px 19px 0px rgba(41, 42, 51, 0.09),
54
+ 0px 27px 26px 0px rgba(41, 42, 51, 0.05),
55
+ 0px 56px 31px 0px rgba(41, 42, 51, 0.01),
56
+ 0px 80px 33px 0px rgba(41, 42, 51, 0);
57
+ }
58
+ ${hoverStyles || ""}
61
59
 
62
- &:hover:not(:active) {
63
- border: 1px solid ${theme.borderColor};
64
- }
60
+ &:hover:not(:active) {
61
+ border: 1px solid ${theme.borderColor};
62
+ }
65
63
 
66
- &:active {
67
- background-color: ${theme.activeBackgroundColor};
68
- border: 1px solid ${theme.borderColor};
69
- ${activeStyles || ""}
70
- }
71
- `;
72
- };
64
+ &:active {
65
+ background-color: ${theme.activeBackgroundColor};
66
+ border: 1px solid ${theme.borderColor};
67
+ ${activeStyles || ""}
68
+ }
69
+ `
70
+ }
71
+ `}
72
+ `;
73
73
 
74
74
  export const Title = styled(Heading)`
75
75
  display: -webkit-box;
@@ -5,19 +5,16 @@ export interface LinkCardProps {
5
5
  variant?: string; // "default" is only one
6
6
  title?: string; // title
7
7
  subtitle?: string; // beneath title
8
- subtitlePadding?: string;
9
8
  themeValues?: any;
10
9
  showLeft?: boolean;
11
10
  leftContent?: JSX.Element;
12
11
  showRight?: boolean;
13
12
  rightContent?: JSX.Element;
14
- href?: string;
13
+ onClick: () => void;
15
14
  extraHoverStyles?: string;
16
15
  extraStyles?: string;
17
16
  extraActiveStyles?: string;
18
17
  titleVariant?: string;
19
- disabled?: boolean;
20
- isExternalLink?: boolean;
21
18
  }
22
19
 
23
20
  export const LinkCard: React.FC<Expand<LinkCardProps> &
@@ -65,6 +65,7 @@ const RegistrationForm = ({
65
65
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
66
66
  autocompleteValue="given-name"
67
67
  dataQa="First name"
68
+ isRequired
68
69
  />
69
70
  <FormInput
70
71
  labelTextWhenNoError="Last name"
@@ -75,6 +76,7 @@ const RegistrationForm = ({
75
76
  onKeyDown={e => e.key === "Enter" && handleSubmit(e)}
76
77
  autocompleteValue="family-name"
77
78
  dataQa="Last name"
79
+ isRequired
78
80
  />
79
81
  <FormInput
80
82
  labelTextWhenNoError="Email address"
@@ -87,6 +89,7 @@ const RegistrationForm = ({
87
89
  isEmail
88
90
  autocompleteValue="email"
89
91
  dataQa="Email address"
92
+ isRequired
90
93
  />
91
94
  <FormInput
92
95
  labelTextWhenNoError="Password"
@@ -98,6 +101,7 @@ const RegistrationForm = ({
98
101
  type="password"
99
102
  autocompleteValue="new-password"
100
103
  dataQa="Password"
104
+ isRequired
101
105
  />
102
106
  <FormInput
103
107
  labelTextWhenNoError="Confirm password"
@@ -109,6 +113,7 @@ const RegistrationForm = ({
109
113
  type="password"
110
114
  autocompleteValue="new-password"
111
115
  dataQa="Confirm password"
116
+ isRequired
112
117
  />
113
118
  <Box padding={isMobile ? "0" : "0.5rem 0 0"}>
114
119
  <PasswordRequirements password={fields.password} isMobile={isMobile} />
@@ -29,7 +29,8 @@ const TermsAndConditionsControlV2 = ({
29
29
  containerBackground = ATHENS_GREY,
30
30
  checkboxMargin = "4px 8px 4px 4px",
31
31
  modalTitle = "Terms and Conditions",
32
- initialFocusSelector = ""
32
+ initialFocusSelector = "",
33
+ isRequired = false
33
34
  }) => {
34
35
  const [showTerms, toggleShowTerms] = useState(false);
35
36
  const standardBoxShadow = generateShadows().standard.base;
@@ -61,6 +62,7 @@ const TermsAndConditionsControlV2 = ({
61
62
  checkboxMargin={checkboxMargin}
62
63
  extraStyles={`align-self: flex-start;`}
63
64
  labelledById={TermsAndConditionsTitleDivId}
65
+ isRequired={isRequired}
64
66
  />
65
67
  )}
66
68
  <Stack childGap="0.25rem" fullHeight>