-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from US-CBP/feature/checklist-horizontal
Feature/checklist horizontal
- Loading branch information
Showing
17 changed files
with
915 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
269 changes: 269 additions & 0 deletions
269
packages/web-components/src/components/cbp-checkbox/cbp-checklist.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
export default { | ||
title: 'Components/Checkbox/Checklist', | ||
//tags: ['autodocs'], | ||
argTypes: { | ||
label: { | ||
control: 'text', | ||
}, | ||
description: { | ||
control: 'text', | ||
}, | ||
fieldId: { | ||
control: 'text', | ||
}, | ||
error: { | ||
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: { | ||
label: "Checklist Group Label", | ||
description: 'Field description.', | ||
checkboxes: [ | ||
{ | ||
label: "Checkbox 1", | ||
name: "checkbox", | ||
value: "1", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 2", | ||
name: "checkbox", | ||
value: "2", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 3", | ||
name: "checkbox", | ||
value: "3", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 4", | ||
name: "checkbox", | ||
value: "4", | ||
checked: false, | ||
disabled: false | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
|
||
|
||
function generateCheckboxes(context, checkboxes) { | ||
const html = checkboxes.map(({ label, name, value, checked, disabled }) => { | ||
return ` | ||
<cbp-checkbox | ||
${context && context != 'light-inverts' ? `context=${context}` : ''} | ||
> | ||
<input | ||
type="checkbox" | ||
name="${name}" | ||
value="${value}" | ||
${checked ? `checked` : ''} | ||
${disabled ? `disabled` : ''} | ||
/> | ||
${label} | ||
</cbp-checkbox>`; | ||
}); | ||
return html.join(''); | ||
} | ||
|
||
const ChecklistTemplate = ({ checkboxes, label, description, fieldId, error, context, sx }) => { | ||
return ` | ||
<cbp-form-field group | ||
${label ? `label="${label}"` : ''} | ||
${description ? `description="${description}"` : ''} | ||
${fieldId ? `field-id="${fieldId}"` : ''} | ||
${error ? `error` : ''} | ||
${context && context != 'light-inverts' ? `context=${context}` : ''} | ||
${sx ? `sx=${JSON.stringify(sx)}` : ''} | ||
> | ||
${generateCheckboxes(context, checkboxes)} | ||
</cbp-form-field> | ||
`; | ||
}; | ||
|
||
export const Checklist = ChecklistTemplate.bind({}); | ||
|
||
|
||
|
||
|
||
const ChecklistHorizontalTemplate = ({ checkboxes, label, description, fieldId, group, error, gap, breakpoint, context, sx }) => { | ||
return ` | ||
<cbp-form-field | ||
${label ? `label="${label}"` : ''} | ||
${description ? `description="${description}"` : ''} | ||
${fieldId ? `field-id="${fieldId}"` : ''} | ||
${group ? `group` : ''} | ||
${error ? `error` : ''} | ||
${context && context != 'light-inverts' ? `context=${context}` : ''} | ||
${sx ? `sx=${JSON.stringify(sx)}` : ''} | ||
> | ||
<cbp-flex | ||
${gap ? `gap="${gap}"` : ''} | ||
${breakpoint ? `breakpoint="${breakpoint}"` : ''} | ||
sx='{"width":"max-content"}' | ||
> | ||
${generateCheckboxes(context, checkboxes)} | ||
</cbp-flex> | ||
</cbp-form-field> | ||
`; | ||
}; | ||
|
||
/* | ||
<cbp-resize-observer> | ||
<cbp-flex gap="var(--cbp-space-5x)" breakpoint="31rem" sx='{"width":"max-content"}'> | ||
${generateCheckboxes(context, checkboxes)} | ||
</cbp-flex> | ||
</cbp-resize-observer> | ||
</cbp-form-field> | ||
*/ | ||
|
||
export const ChecklistHorizontal = ChecklistHorizontalTemplate.bind({}); | ||
ChecklistHorizontal.args = { | ||
gap: 'var(--cbp-space-5x)', | ||
breakpoint: '35rem' | ||
} | ||
|
||
|
||
|
||
const ChecklistMultiColumnTemplate = ({ checkboxes, gap, columns, width, label, description, fieldId, group, error, context, sx }) => { | ||
return ` | ||
<cbp-form-field | ||
${label ? `label="${label}"` : ''} | ||
${description ? `description="${description}"` : ''} | ||
${fieldId ? `field-id="${fieldId}"` : ''} | ||
${group ? `group` : ''} | ||
${error ? `error` : ''} | ||
${context && context != 'light-inverts' ? `context=${context}` : ''} | ||
${sx ? `sx=${JSON.stringify(sx)}` : ''} | ||
> | ||
<cbp-multicol nobreak | ||
${gap ? `gap="${gap}"` : ''} | ||
${columns ? `columns="${columns}"` : ''} | ||
${width ? `width="${width}"` : ''} | ||
> | ||
${generateCheckboxes(context, checkboxes)} | ||
</cbp-multicol> | ||
</cbp-form-field> | ||
`; | ||
}; | ||
|
||
export const ChecklistMultiColumn = ChecklistMultiColumnTemplate.bind({}); | ||
ChecklistMultiColumn.args = { | ||
gap: 'var(--cbp-space-4x)', | ||
columns: '3', | ||
width: '10rem', | ||
checkboxes: [ | ||
{ | ||
label: "Checkbox 1", | ||
name: "checkbox", | ||
value: "1", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 2", | ||
name: "checkbox", | ||
value: "2", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 3", | ||
name: "checkbox", | ||
value: "3", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 4", | ||
name: "checkbox", | ||
value: "4", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 5", | ||
name: "checkbox", | ||
value: "5", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 6", | ||
name: "checkbox", | ||
value: "6", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 7", | ||
name: "checkbox", | ||
value: "7", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 8", | ||
name: "checkbox", | ||
value: "8", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 9", | ||
name: "checkbox", | ||
value: "9", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 10", | ||
name: "checkbox", | ||
value: "10", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 11", | ||
name: "checkbox", | ||
value: "11", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 12", | ||
name: "checkbox", | ||
value: "12", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 13", | ||
name: "checkbox", | ||
value: "13", | ||
checked: false, | ||
disabled: false | ||
}, | ||
{ | ||
label: "Checkbox 14", | ||
name: "checkbox", | ||
value: "14", | ||
checked: false, | ||
disabled: false | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.