Skip to content

Commit

Permalink
Merge pull request #212 from US-CBP/bugfix/accordion-title-slotted
Browse files Browse the repository at this point in the history
Bugfix/accordion title slotted
  • Loading branch information
dgibson666 authored Oct 15, 2024
2 parents 0d91e6a + f88a66d commit 997d0c2
Show file tree
Hide file tree
Showing 15 changed files with 7,234 additions and 8,808 deletions.
15,740 changes: 7,061 additions & 8,679 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@
],
"devDependencies": {
"@types/node": "^20.10.4",
"@whitespace/storybook-addon-html": "^6.1.1",
"eslint": "^8.55.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"lerna": "^8.1.8",
"postcss-scss": "^4.0.9",
"prettier": "^2.8.8",
"prettier": "^3.0.0",
"react-syntax-highlighter": "^15.5.0",
"stylelint": "^14.16.1",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-recommended": "^9.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/web-components/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const config = {
//getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@storybook/addon-a11y'),
getAbsolutePath("@storybook/addon-mdx-gfm"),
getAbsolutePath("@storybook/addon-mdx-gfm"),
'@chromatic-com/storybook'
],
framework: {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-components/.storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<link rel="icon" type="image/x-icon" href="assets/images/cbp-seal.svg">
<link rel="icon" type="image/svg+xml" href="assets/images/cbp-seal.svg">
7 changes: 5 additions & 2 deletions packages/web-components/.storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { addons } from '@storybook/addons';
import { addons } from '@storybook/manager-api';
import { themes } from '@storybook/theming';
//import { addons } from '@storybook/addons';
import CBPTheme from './theme';

addons.setConfig({
theme,
theme: CBPTheme,
//theme: themes.dark,
toolbar: {
//zoom: { hidden: true }
Expand Down
6 changes: 3 additions & 3 deletions packages/web-components/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ const stencilWrapper = (storyFn, context) => {
export const decorators = [
withWrapper,
//stencilWrapper,
/*

withThemeByDataAttribute({
themes: {
light: 'light',
dark: 'dark',
},
defaultTheme: 'light',
//defaultTheme: 'light',
attributeName: 'data-cbp-theme',
}),
*/
//*/
];

2 changes: 1 addition & 1 deletion packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"build-pages": "storybook build --output-dir storybook-static"
},
"dependencies": {
"@stencil/core": "^4.15.0",
"@stencil/core": "^4.22.0",
"lerna": "8.1.8"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ cbp-accordion-item {
}

.cbp-accordion-item--control {
display: block;
display: flex;
flex-direction: var(--cbp-accordion-item-control-direction, row);
align-items: center;
gap: var(--cbp-accordion-item-control-gap);
min-height: var(--cbp-space-13x);
color: var(--cbp-accordion-item-color);
Expand All @@ -102,6 +103,22 @@ cbp-accordion-item {
outline-offset: calc(-1 * var(--cbp-space-1x));
cursor: pointer;

.cbp-accordion-item--heading {
display: flex;
flex-grow: 1;
justify-content: space-between;

:first-child {
flex-grow: 1;
}

[slot="cbp-accordion-item-label"] {
display: flex;
align-items: center;
}

}

/* TechDebt: having trouble with this override using CSS variables. */
cbp-typography,
cbp-typography > * {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { setCSSProps, createNamespaceKey } from '../../utils/utils';

/**
* @slot - Accordion Item content is placed in the default slot.
* @slot cbp-accordion-label - Optionally, an Accordion Item heading with markup may be placed in this slot rather than via the labal property.
* @slot cbp-accordion-item-label - Optionally, an Accordion Item heading with markup may be placed in this slot rather than via the labal property.
*/
@Component({
tag: 'cbp-accordion-item',
Expand Down Expand Up @@ -66,34 +66,29 @@ export class CbpAccordionItem {
render() {
return (
<Host>
<cbp-flex
<div
class="cbp-accordion-item--control"
align-items="center"
onClick={() => this.handleClick()}
>
<cbp-flex-item>
<cbp-button
type="button"
class="cbp-accordion-item--toggle"
fill="ghost"
color="secondary"
controls={`${this.headingId}-content`}
expanded={this.open}
accessibilityText="Toggle Accordion Item"
aria-describedby={this.headingId}
ref={el => (this.control = el)}
>
<cbp-icon name="chevron-right"></cbp-icon>
</cbp-button>
</cbp-flex-item>
<cbp-button
type="button"
class="cbp-accordion-item--toggle"
fill="ghost"
color="secondary"
controls={`${this.headingId}-content`}
expanded={this.open}
accessibilityText="Toggle Accordion Item"
aria-describedby={this.headingId}
ref={el => (this.control = el)}
>
<cbp-icon name="chevron-right"></cbp-icon>
</cbp-button>

<cbp-flex-item id={this.headingId} flex-grow="1">
{ this.host.querySelector('[slot="cbp-accordion-label"]')
? <slot name="cbp-accordion-label" />
: <cbp-typography tag={this.headingLevel} variant="heading-sm">{this.label}</cbp-typography>
}
</cbp-flex-item>
</cbp-flex>
<div id={this.headingId} class="cbp-accordion-item--heading">
<slot name="cbp-accordion-item-label" />
{this.label && <cbp-typography tag={this.headingLevel} variant="heading-sm">{this.label}</cbp-typography>}
</div>
</div>

<div id={`${this.headingId}-content`} class="cbp-accordion-item--content">
<slot />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,88 +1,121 @@
export default {
title: 'Components/Accordion',
tags: ['autodocs'],
argTypes: {
items: {
name: 'Accordion Items',
description: 'Configure various aspects of the accordion items within the accordion.',
control: 'object',
title: 'Components/Accordion',
tags: ['autodocs'],
argTypes: {
items: {
name: 'Accordion Items',
description: 'Configure various aspects of the accordion items within the accordion.',
control: 'object',
},
multiple: {
description: 'Specifies whether multiple accordion items may remain open at the same time.',
control: 'boolean',
},
context: {
control: 'select',
options: ['light-inverts', 'light-always', 'dark-inverts', 'dark-always'],
},
sx: {
description: 'Supports adding inline styles as an object of key-value pairs comprised of CSS properties and values. Values should reference design tokens when possible.',
control: 'object',
},
},
args: {
items: [
{
label: 'Accordion Item 1',
open: false,
headingLevel: '',
color: 'default',
content: 'Accordion item 1 content.',
},
multiple: {
description: 'Specifies whether multiple accordion items may remain open at the same time.',
control: 'boolean',
{
label: 'Accordion Item 2',
open: false,
headingLevel: '',
color: 'default',
content: 'Accordion item 2 content.',
},
context : {
control: 'select',
options: [ "light-inverts", "light-always", "dark-inverts", "dark-always"]
{
label: 'Accordion Item 3',
open: false,
headingLevel: '',
color: 'danger',
content: 'Accordion item 3 content.',
},
sx: {
description: 'Supports adding inline styles as an object of key-value pairs comprised of CSS properties and values. Values should reference design tokens when possible.',
control: 'object',
{
label: 'Accordion Item 4',
open: false,
headingLevel: '',
color: 'default',
content: 'Accordion item 4 content.',
},
},
args: {
items: [
{
label: 'Accordion Item 1',
open: false,
headingLevel: '',
color: 'default',
content: 'Accordion item 1 content.',
},
{
label: 'Accordion Item 2',
open: false,
headingLevel: '',
color: 'default',
content: 'Accordion item 2 content.',
},
{
label: 'Accordion Item 3',
open: false,
headingLevel: '',
color: 'danger',
content: 'Accordion item 3 content.',
},
{
label: 'Accordion Item 4',
open: false,
headingLevel: '',
color: 'default',
content: 'Accordion item 4 content.',
},
],
},
};

],
},
};

function generateChildren(items) {
const html = items.map(({ label, content, open, color, headingLevel }) => {
return `
<cbp-accordion-item
${label ? `label="${label}"` : ''}
${open == true ? 'open' : ''}
${color === 'danger' ? `color=${color}` : ''}
${headingLevel ? `heading-level=${headingLevel}` : ''}
>
${content}
</cbp-accordion-item>
`;
});
return html.join('');
}

const Template = ({ items, multiple, context, sx }) => {
return `
<cbp-accordion
${multiple ? `multiple` : ''}
${context && context != 'light-inverts' ? `context=${context}` : ''}
${sx ? `sx=${JSON.stringify(sx)}` : ''}
>
${generateChildren(items)}
</cbp-accordion>
`;
};

export const Accordion = Template.bind({});
Accordion.args = {};



function generateChildren(items) {
const html = items.map(({ label, content, open, color, headingLevel }) => {
return `
<cbp-accordion-item
${label ? `label="${label}"` : ''}
${open == true ? 'open' : ''}
${color === 'danger' ? `color=${color}` : ''}
${headingLevel ? `heading-level=${headingLevel}` : ''}
>
${content}
</cbp-accordion-item>
`;
});
return html.join('');
}

function generateSlottedChildren(items) {
const html = items.map(({ label, content, open, color, headingLevel }) => {
return `
<cbp-accordion-item
${open == true ? 'open' : ''}
${color === 'danger' ? `color=${color}` : ''}
>
<div slot="cbp-accordion-item-label">
<cbp-typography ${headingLevel ? `tag=${headingLevel}` : ''} variant="heading-sm">${label}</cbp-typography>
<cbp-badge>55</cbp-badge>
</div>
${content}
</cbp-accordion-item>
`;
});
return html.join('');
}

const Template = ({ items, multiple, context, sx }) => {
return `
<cbp-accordion
${multiple ? `multiple` : ''}
${context && context != 'light-inverts' ? `context=${context}` : ''}
${sx ? `sx=${JSON.stringify(sx)}` : ''}
>
${generateChildren(items)}
</cbp-accordion>
`;
};
const AccordionWithSlottedLabelTemplate = ({ items, multiple, context, sx }) => {
return `
<cbp-accordion
${multiple ? `multiple` : ''}
${context && context != 'light-inverts' ? `context=${context}` : ''}
${sx ? `sx=${JSON.stringify(sx)}` : ''}
>
${generateSlottedChildren(items)}
</cbp-accordion>
`;
};

export const Accordion = Template.bind({});
Accordion.args = {}
export const AccordionWithSlottedLabel = AccordionWithSlottedLabelTemplate.bind({});
AccordionWithSlottedLabel.args = {};
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class CbpButton {
/** A custom event emitted when the component has completed loading and its internal lifecycles. */
@Event() componentLoad!: EventEmitter;


handleClick() {
// If this is a control for something, manage state through stencil store
if (this.controls) {
Expand All @@ -103,9 +104,7 @@ export class CbpButton {
}
}

//console.log('this.button',this.button);

this.buttonClick.emit({
this.buttonClick?.emit({
host: this.host,
nativeElement: this.button,
controls: this.controls ? this.controls : null,
Expand Down
Loading

0 comments on commit 997d0c2

Please sign in to comment.