-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for accordions with additional labels (#3437)
Co-authored-by: Josh Wooding <[email protected]> Co-authored-by: Fernanda Castillo <[email protected]>
- Loading branch information
1 parent
f44fe1e
commit f8de151
Showing
13 changed files
with
318 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@salt-ds/core": patch | ||
--- | ||
|
||
Fixed the chevron alignment for multi-line accordions. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { ChangeEvent, ReactElement, useState } from "react"; | ||
import { | ||
Accordion, | ||
AccordionGroup, | ||
AccordionHeader, | ||
AccordionPanel, | ||
CheckboxGroup, | ||
Checkbox, | ||
Label, | ||
SplitLayout, | ||
StackLayout, | ||
Text, | ||
FormField, | ||
FormFieldLabel, | ||
} from "@salt-ds/core"; | ||
|
||
const accounts = [ | ||
{ name: "Account 1", number: "8736" }, | ||
{ name: "Account 2", number: "2564" }, | ||
]; | ||
|
||
const features = [ | ||
{ | ||
name: "Domestic wires", | ||
id: "domestic_wires", | ||
description: "Initiate wire transfers to another bank", | ||
}, | ||
{ | ||
name: "Account transfers", | ||
id: "account_transfers", | ||
description: "Move money within your accounts", | ||
}, | ||
]; | ||
|
||
export const AdditionalLabels = (): ReactElement => { | ||
const [state, setState] = useState<Record<string, string[]>>({ | ||
domestic_wires: [], | ||
account_transfers: [], | ||
}); | ||
|
||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
const value = event.target.value; | ||
const name = event.target.name; | ||
|
||
setState((prev) => ({ | ||
...prev, | ||
[name]: prev[name].includes(value) | ||
? prev[name].filter((account) => account !== value) | ||
: [...prev[name], value], | ||
})); | ||
}; | ||
|
||
return ( | ||
<div style={{ width: "80%", height: "100%" }}> | ||
<AccordionGroup> | ||
{Object.values(features).map(({ name, description, id }) => ( | ||
<Accordion value={id}> | ||
<AccordionHeader> | ||
<StackLayout gap={0.5}> | ||
<SplitLayout | ||
align="baseline" | ||
startItem={ | ||
<Text> | ||
<strong>{name}</strong> | ||
</Text> | ||
} | ||
endItem={ | ||
<Text styleAs="label" color="secondary"> | ||
{state[id].length} of {accounts.length} accounts | ||
</Text> | ||
} | ||
/> | ||
<Text styleAs="label" color="secondary"> | ||
{description} | ||
</Text> | ||
</StackLayout> | ||
</AccordionHeader> | ||
<AccordionPanel> | ||
<FormField> | ||
<FormFieldLabel>Accounts for this service</FormFieldLabel> | ||
<CheckboxGroup | ||
checkedValues={state[id]} | ||
onChange={handleChange} | ||
direction="horizontal" | ||
> | ||
{accounts.map(({ name, number }) => ( | ||
<Checkbox | ||
label={`${name} (...${number})`} | ||
name={id} | ||
value={number} | ||
/> | ||
))} | ||
</CheckboxGroup> | ||
</FormField> | ||
</AccordionPanel> | ||
</Accordion> | ||
))} | ||
</AccordionGroup> | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.