Skip to content

Commit 48b0c74

Browse files
authored
Merge pull request #225 from US-CBP/bugfix/check-radio
Bugfix/check radio
2 parents 9017532 + f23a416 commit 48b0c74

File tree

10 files changed

+101
-75
lines changed

10 files changed

+101
-75
lines changed

packages/web-components/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ This CHANGELOG.md tracks the updates to the web components package of the CBP de
44

55
The React components are wrappers generated from this package and will share the same changes.
66

7+
## [unpublished] TBD
8+
* Published the Change log to Storybook.
9+
* Published Stencil-generated component API docs to Storybook. We will continually revisit these for completion.
10+
711
## [0.0.1-develop.16] 10-28-2024
812
* First cut of `cbp-checkbox`.
913
* First cut of `cbp-radio`.
1014
* First cut of `cbp-toast`.
1115
* Updated `cbp-form-field` with the ability to handle input groups (e.g., checklist, radio list, compound inputs) with more than a single input.
1216
* Updated Structured list with selectable functionality.
13-
* Fixed the issue with slotted Accordion title being hidden.
17+
* Fixed the issue with slotted Accordion Item title being hidden (the slot name was also updated to `cbp-accordion-item-title` to follow our naming conventions).
1418

1519
## [0.0.1-develop.15] 10-07-2024
1620

@@ -90,7 +94,7 @@ The React components are wrappers generated from this package and will share the
9094
* Breaking: Deprecated/removed `cbp-visuallyhidden` since its functionality was included in cbp-hide.
9195
* First cut of `cbp-hide`, a component that allows content to be programmatically hidden (or visually hidden) based on property or media query.
9296
* Updated designs of `cbp-badge`, `cbp-chip`, and `cbp-tag` to use the correct design tokens.
93-
* Updated the cbp-chip component by adding `name` and `value` properties and updating the custom event.
97+
* Updated the `cbp-chip` component by adding `name` and `value` properties and updating the custom event.
9498
* Updated Template and Universal Header stories to use `cbp-hide` for responsiveness.
9599
* Updated the Template to wrap the Universal Header and Application Header in an HTML5 `header` landmark tag.
96100

packages/web-components/src/components/cbp-checkbox/cbp-checkbox.scss

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,18 @@ cbp-checkbox {
107107
position: relative;
108108

109109
label {
110-
display: flex;
110+
display: grid;
111+
grid-template-columns: var(--cbp-space-7x) 1fr;
111112
align-items: center;
113+
gap: var(--cbp-space-2x);
112114
min-height: var(--cbp-checkbox-min-height);
113115
font-weight: var(--cbp-checkbox-font-weight-label);
114116
color: var(--cbp-checkbox-color-label);
115117
}
116118

117119
input[type=checkbox] {
118-
position: relative;
119-
flex-shrink: 0;
120+
display: grid;
121+
place-content: center;
120122
appearance: none; // checkboxes do not accept styling per design specs
121123
color: var(--cbp-checkbox-color);
122124
background-color: var(--cbp-checkbox-color-bg);
@@ -127,21 +129,15 @@ cbp-checkbox {
127129
height: var(--cbp-space-6x);
128130
width: var(--cbp-space-6x);
129131
margin: 0;
130-
margin-inline-end: var(--cbp-space-2x);
131132
outline: 0;
132133
box-shadow: 0 0 0 calc(var(--cbp-space-5x) / 2) var(--cbp-checkbox-color-halo);
133134
clip-path: circle(86%);
134135

135136
// Check Mark/Dash
136137
&::before {
137138
content: '';
138-
position: absolute;
139-
margin: auto;
140-
left: 0;
141-
right: 0;
142-
bottom: 0;
143139
overflow: hidden;
144-
top: 0;
140+
//transform: scale(0);
145141
}
146142

147143
// Verified: only need to set the base variables with higher level tokens that are swapped for dark mode
@@ -176,22 +172,22 @@ cbp-checkbox {
176172
&:checked {
177173
// Check Mark
178174
&::before {
179-
border-right: solid var(--cbp-border-size-lg) var(--cbp-checkbox-color);
180-
border-bottom: solid var(--cbp-border-size-lg) var(--cbp-checkbox-color);
175+
height: var(--cbp-space-4x);
176+
width: var(--cbp-space-2x);
177+
border-right: solid var(--cbp-border-size-xl) var(--cbp-checkbox-color);
178+
border-bottom: solid var(--cbp-border-size-xl) var(--cbp-checkbox-color);
181179
//border-radius: 1px;
182-
height: 70%;
183-
width: 35%;
184180
transform: rotate(45deg) translateY(-10%) translateX(-10%);
185181
}
186182
}
187183

188184
&:indeterminate {
189185
// Indeterminate dash
190186
&::before {
187+
height: 0;
188+
width: var(--cbp-space-4x);
191189
border: solid var(--cbp-border-size-md) var(--cbp-checkbox-color);
192190
border-radius: var(--cbp-border-radius-soft);
193-
height: 0;
194-
width: 60%;
195191
}
196192
}
197193

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
cbp-flex-item:not([hidden]) {
22
display: block;
3-
position: relative;
4-
}
3+
}
Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,55 @@
11
import { Component, Prop, Element, Host, h} from '@stencil/core';
22
import { setCSSProps } from '../../utils/utils';
33

4+
/**
5+
* @slot - Content slotted in the default slot may consist of any combination of text or DOM nodes.
6+
*/
47
@Component({
5-
tag: 'cbp-flex-item',
6-
styleUrl: 'cbp-flex-item.scss',
8+
tag: 'cbp-flex-item',
9+
styleUrl: 'cbp-flex-item.scss',
710
})
811
export class CbpFlexItem {
912

10-
@Element() host: HTMLElement;
13+
@Element() host: HTMLElement;
1114

12-
@Prop() alignSelf: "auto" | "stretch" | "flex-start" | "flex-end" | "center" | "baseline";
13-
@Prop() order: number;
14-
@Prop() flexGrow: number;
15-
@Prop() flexShrink: number;
16-
@Prop() flexBasis: string;
17-
/** Supports adding inline styles as an object */
18-
@Prop() sx: any = {};
15+
/** Specifies the alignment of the specific flex item along the cross-axis separate from the parent context. */
16+
@Prop() alignSelf: "auto" | "stretch" | "flex-start" | "flex-end" | "center" | "baseline";
17+
18+
/** Specifies an ordinal group value for sorting this flex item within its group. Defaults to zero, which renders the items in DOM order. */
19+
@Prop() order: number;
20+
21+
/** Specifies the growth factor the item will grow at relative to other items. Defaults to zero, as flex items do not grow by default. */
22+
@Prop() flexGrow: number;
23+
24+
/** Specifies the shrink factor the item will shrink at relative to other items. Defaults to 1, as flex items will shrink at an equal rate by default, taking content size into consideration. */
25+
@Prop() flexShrink: number;
26+
27+
/** Specifies a basis (in CSS units or content values) for calculating flex behavior different from the default of "auto" (which usually evaluates to "content"). */
28+
@Prop() flexBasis: string;
1929

30+
/** Supports adding inline styles as an object */
31+
@Prop() sx: any = {};
2032

21-
componentWillLoad() {
22-
if (typeof this.sx == "string") {
23-
this.sx = JSON.parse(this.sx) || {}
24-
}
25-
setCSSProps(this.host, {
26-
'align-self': this.alignSelf,
27-
'order': this.order,
28-
'flex-grow': this.flexGrow,
29-
'flex-shrink': this.flexShrink,
30-
'flex-basis': this.flexBasis,
31-
...this.sx
32-
});
33-
}
3433

35-
render() {
36-
return (
37-
<Host>
38-
<slot />
39-
</Host>
40-
);
34+
componentWillLoad() {
35+
if (typeof this.sx == "string") {
36+
this.sx = JSON.parse(this.sx) || {}
4137
}
38+
setCSSProps(this.host, {
39+
'align-self': this.alignSelf,
40+
'order': this.order,
41+
'flex-grow': this.flexGrow,
42+
'flex-shrink': this.flexShrink,
43+
'flex-basis': this.flexBasis,
44+
...this.sx
45+
});
46+
}
47+
48+
render() {
49+
return (
50+
<Host>
51+
<slot />
52+
</Host>
53+
);
54+
}
4255
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cbp-flex:not([hidden]) {
22
display: flex;
33

4-
&[display='inline-flex'] {
4+
&[display="inline-flex"] {
55
display: inline-flex;
66
}
77
}

packages/web-components/src/components/cbp-flex/cbp-flex.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,8 @@ const Template = ({ display, wrap, direction, alignItems, alignContent, justifyC
9191

9292
export const Flex = Template.bind({});
9393
Flex.args = {};
94+
95+
96+
/* For testing of sx and setCSSProps()
97+
sx='{"border":"var(--cbp-border-size-lg) solid var(--cbp-color-red-20)","height":"200px","border-top-width":"0px"}'
98+
*/

packages/web-components/src/components/cbp-flex/cbp-flex.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
11
import { Component, Prop, Element, Host, h } from '@stencil/core';
22
import { setCSSProps } from '../../utils/utils';
33

4+
/**
5+
* @slot - DOM nodes placed in the default slot automatically become flex children. The use of `cbp-flex-item` is only required for granular control of individual flex item properties.
6+
*/
47
@Component({
58
tag: 'cbp-flex',
69
styleUrl: 'cbp-flex.scss',
710
})
811
export class CbpFlex {
912
@Element() host: HTMLElement;
1013

14+
/** Specifies the display mode. Defaults to "flex" */
1115
@Prop({ reflect: true }) display: 'flex' | 'inline-flex' = 'flex';
16+
17+
/** Specifies the wrapping behavior of the flex children. Browser default behavior is "nowrap". */
1218
@Prop() wrap: 'nowrap' | 'wrap' | 'wrap-reverse';
19+
20+
/** Specifies how flex items are placed in the flex container by setting the direction of the flex container’s main axis. Defaults to "row" for a horizontal flex context. */
1321
@Prop() direction: 'row' | 'row-reverse' | 'column' | 'column-reverse' = 'row';
22+
23+
/** Specifies the alignment for all of the flex container’s items along the cross-axis. Defaults to "stretch". */
1424
@Prop() alignItems: 'auto' | 'stretch' | 'flex-start' | 'flex-end' | 'center' | 'baseline' = 'stretch';
25+
26+
/** Specifies the alignment of a flex container's items within the flex container (only when there is extra space in the cross-axis). */
1527
@Prop() alignContent: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'stretch' = 'stretch';
28+
29+
/** Specifies the alignment of flex items along the main axis (of the current line) of the flex container. */
1630
@Prop() justifyContent: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly' = 'flex-start';
31+
32+
/** Specifies the gap between items in CSS units (preferably relative units such as rem). Accepts a single value for horizontal and vertical gap or two values representing column gap and row gap, respectively. */
1733
@Prop() gap: string;
34+
35+
/** Specifies the size at which the flex children are linearized, specified in CSS units (preferably relative units such as rem). */
1836
@Prop() breakpoint: string;
37+
38+
/** Not yet implemented */
1939
@Prop() contentBreakpoint: string;
40+
2041
/** Supports adding inline styles as an object */
2142
@Prop() sx: any = {};
2243

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Meta, Markdown } from "@storybook/blocks";
22
import Docs from './readme.md?raw';
33

4-
<Meta title="Components/Form Field/API Docs" />
4+
<Meta title="Components/Form Fields/API Docs" />
55

66
<Markdown>{Docs}</Markdown>

packages/web-components/src/components/cbp-radio/cbp-radio.scss

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,56 +103,43 @@
103103
}
104104

105105
cbp-radio {
106-
//display: block;
107-
display: grid;
108-
place-content: center;
106+
display: block;
109107
margin: var(--cbp-radio-margin);
110108
position: relative;
111109

112110
label {
113-
display: flex;
111+
display: grid;
112+
grid-template-columns: var(--cbp-space-7x) 1fr;
114113
align-items: center;
114+
gap: var(--cbp-space-2x);
115115
min-height: var(--cbp-radio-min-height);
116116
font-weight: var(--cbp-radio-font-weight-label);
117117
color: var(--cbp-radio-color-label);
118118
}
119119

120120
input[type=radio] {
121-
position: relative;
122-
flex-shrink: 0;
121+
display: grid;
122+
place-content: center;
123123
appearance: none; // radios do not accept styling per design specs
124-
//color: var(--cbp-radio-color);
125124
background-color: var(--cbp-radio-color-bg);
126125
border-color: var(--cbp-radio-color-border);
127126
border-style: solid;
128127
border-width: var(--cbp-border-size-md);
129128
border-radius: var(--cbp-border-radius-circle);
130-
// TechDebt: Testing which one works: seeing different results on different computers/base font sizes
131129
height: var(--cbp-space-7x);
132130
width: var(--cbp-space-7x);
133-
//height: calc(var(--cbp-space-7x) - 1px);
134-
//width: calc(var(--cbp-space-7x) - 1px);
135131
margin: 0;
136-
margin-inline-end: var(--cbp-space-2x);
137132
outline: 0;
138133
box-shadow: 0 0 0 calc(var(--cbp-space-5x) / 2) var(--cbp-radio-color-halo);
139134
clip-path: circle(80%); // verified
140135

141-
// Check Mark/Dash
136+
// Radio marker
142137
&::before {
143138
content: '';
144-
position: absolute;
145-
margin: auto;
146-
left: 0;
147-
right: 0;
148-
top: 0;
149-
bottom: 0;
150139
overflow: hidden;
151140
height: var(--cbp-space-4x);
152141
width: var(--cbp-space-4x);
153142
transform: scale(0);
154-
//height: 0;
155-
//width: 0;
156143
background-color: var(--cbp-radio-color-checked);
157144
border-radius: var(--cbp-border-radius-circle);
158145
}

packages/web-components/src/utils/utils.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ export const getFocusableElements = (scope: HTMLElement) => {
2929
export const setCSSProps = <T extends { [key: string]: any }>(host: HTMLElement, { ...props }: T): void => {
3030
Object.entries(props).forEach(([key, value]): void => {
3131
try {
32-
//console.log('setCSSProps: ',{host},{key},{value}, typeof value);
33-
// Any value other than undefined is coerced into a string?
34-
//host.style.setProperty(key, value != undefined ? value : '');
32+
// Still testing: Anything undefined should be skipped. Any other value is coerced into a string?
33+
if (value != undefined) {
34+
//console.log('setCSSProps: ', host, key, value, typeof value);
35+
host.style.setProperty(key, value);
36+
}
3537

36-
typeof value == 'string' ? host.style.setProperty(key, value) : host.style.setProperty(key, value != undefined ? `${value}` : '');
3738
} catch (e) {
3839
console.log('Error in setCSSProps: ', { host }, { key }, { value }, { e });
3940
}

0 commit comments

Comments
 (0)