Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom variant to DropdownToggle #704

Merged
merged 8 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
329 changes: 329 additions & 0 deletions spec/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4971,6 +4971,92 @@ exports[`Storyshots Components/Copy To Clipboard Default 1`] = `
</div>
`;

exports[`Storyshots Components/Dropdown Custom Toggle 1`] = `
<div
style={
Object {
"padding": "1rem",
}
}
>
<div
className="Dropdown dropdown"
>
<button
aria-expanded={false}
aria-label="dropdown-toggle"
className="DropdownToggle DropdownToggle--custom DropdownToggle--no-caret btn btn-primary"
disabled={false}
onClick={[Function]}
type="button"
>
<div
style={
Object {
"alignItems": "center",
"backgroundColor": "#444444",
"display": "flex",
"flexDirection": "row",
"justifyContent": "space-between",
"padding": "12px",
"width": "200px",
}
}
>
<div>
<div
style={
Object {
"fontSize": "18px",
"fontWeight": "700",
}
}
>
Team A
</div>
<div
style={
Object {
"backgroundColor": "#444444",
"fontSize": "12px",
"fontWeight": "400",
}
}
>
Organization
</div>
</div>
<div
style={
Object {
"marginRight": "4px",
}
}
>
<svg
aria-hidden="true"
className="svg-inline--fa fa-chevron-down fa-w-14 "
data-icon="chevron-down"
data-prefix="fas"
focusable="false"
role="img"
style={Object {}}
viewBox="0 0 448 512"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"
fill="currentColor"
style={Object {}}
/>
</svg>
</div>
</div>
</button>
</div>
</div>
`;

exports[`Storyshots Components/Dropdown Default 1`] = `
<div
style={
Expand Down Expand Up @@ -19604,6 +19690,249 @@ exports[`Storyshots Components/Toast Toast With Action 1`] = `
</div>
`;

exports[`Storyshots Components/ToggleInput Checked 1`] = `
<div
style={
Object {
"padding": "1rem",
}
}
>
<label
className="ToggleInput__label"
htmlFor="1"
>
<div
className="react-toggle react-toggle--checked"
onClick={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
>
<div
className="react-toggle-track"
>
<div
className="react-toggle-track-check"
>
<svg
height="11"
viewBox="0 0 14 11"
width="14"
>
<title>
switch-check
</title>
<path
d="M11.264 0L5.26 6.004 2.103 2.847 0 4.95l5.26 5.26 8.108-8.107L11.264 0"
fill="#fff"
fillRule="evenodd"
/>
</svg>
</div>
<div
className="react-toggle-track-x"
>
<svg
height="10"
viewBox="0 0 10 10"
width="10"
>
<title>
switch-x
</title>
<path
d="M9.9 2.12L7.78 0 4.95 2.828 2.12 0 0 2.12l2.83 2.83L0 7.776 2.123 9.9 4.95 7.07 7.78 9.9 9.9 7.776 7.072 4.95 9.9 2.12"
fill="#fff"
fillRule="evenodd"
/>
</svg>
</div>
</div>
<div
className="react-toggle-thumb"
/>
<input
checked={true}
className="react-toggle-screenreader-only"
disabled={false}
id="1"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="checkbox"
value="true"
/>
</div>
<span>
Label
</span>
</label>
</div>
`;

exports[`Storyshots Components/ToggleInput Default 1`] = `
<div
style={
Object {
"padding": "1rem",
}
}
>
<label
className="ToggleInput__label"
htmlFor="1"
>
<div
className="react-toggle"
onClick={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
>
<div
className="react-toggle-track"
>
<div
className="react-toggle-track-check"
>
<svg
height="11"
viewBox="0 0 14 11"
width="14"
>
<title>
switch-check
</title>
<path
d="M11.264 0L5.26 6.004 2.103 2.847 0 4.95l5.26 5.26 8.108-8.107L11.264 0"
fill="#fff"
fillRule="evenodd"
/>
</svg>
</div>
<div
className="react-toggle-track-x"
>
<svg
height="10"
viewBox="0 0 10 10"
width="10"
>
<title>
switch-x
</title>
<path
d="M9.9 2.12L7.78 0 4.95 2.828 2.12 0 0 2.12l2.83 2.83L0 7.776 2.123 9.9 4.95 7.07 7.78 9.9 9.9 7.776 7.072 4.95 9.9 2.12"
fill="#fff"
fillRule="evenodd"
/>
</svg>
</div>
</div>
<div
className="react-toggle-thumb"
/>
<input
checked={false}
className="react-toggle-screenreader-only"
disabled={false}
id="1"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="checkbox"
value="false"
/>
</div>
<span>
Label
</span>
</label>
</div>
`;

exports[`Storyshots Components/ToggleInput Label Left 1`] = `
<div
style={
Object {
"padding": "1rem",
}
}
>
<label
className="ToggleInput__label"
htmlFor="1"
>
<span>
Label
</span>
<div
className="react-toggle"
onClick={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
>
<div
className="react-toggle-track"
>
<div
className="react-toggle-track-check"
>
<svg
height="11"
viewBox="0 0 14 11"
width="14"
>
<title>
switch-check
</title>
<path
d="M11.264 0L5.26 6.004 2.103 2.847 0 4.95l5.26 5.26 8.108-8.107L11.264 0"
fill="#fff"
fillRule="evenodd"
/>
</svg>
</div>
<div
className="react-toggle-track-x"
>
<svg
height="10"
viewBox="0 0 10 10"
width="10"
>
<title>
switch-x
</title>
<path
d="M9.9 2.12L7.78 0 4.95 2.828 2.12 0 0 2.12l2.83 2.83L0 7.776 2.123 9.9 4.95 7.07 7.78 9.9 9.9 7.776 7.072 4.95 9.9 2.12"
fill="#fff"
fillRule="evenodd"
/>
</svg>
</div>
</div>
<div
className="react-toggle-thumb"
/>
<input
checked={false}
className="react-toggle-screenreader-only"
disabled={false}
id="1"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
type="checkbox"
value="false"
/>
</div>
</label>
</div>
`;

exports[`Storyshots Components/Tooltip Default 1`] = `
<div
style={
Expand Down
7 changes: 7 additions & 0 deletions src/Dropdown/Dropdown.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ Avoid the Dropdown component if:
<Story id="components-dropdown--icon-swap" />
</Canvas>

### Custom Toggle
- Use the `custom` and `removeCaret` prop on `DropdownToggle` to remove default styling.

<Canvas>
<Story id="components-dropdown--custom-toggle" />
</Canvas>


## Formatting

Expand Down
32 changes: 31 additions & 1 deletion src/Dropdown/Dropdown.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import {
Dropdown, DropdownToggle, DropdownItem, DropdownMenu,
} from 'src/Dropdown';
import { faEllipsisV, faFileAlt } from '@fortawesome/pro-solid-svg-icons';
import { faEllipsisV, faFileAlt, faChevronDown } from '@fortawesome/pro-solid-svg-icons';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import mdx from './Dropdown.mdx';
Expand Down Expand Up @@ -101,3 +101,33 @@ export const IconSwap = () => (
</Dropdown>
</>
);

export const CustomToggle = () => (
<Dropdown>
<DropdownToggle custom removeCaret>
<div style={{
padding: '12px',
backgroundColor: '#444444',
width: '200px',
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
}}
Comment on lines +108 to +116
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for story purposes, this can all be done via scss file and className

>
<div>
<div style={{ fontSize: '18px', fontWeight: '700' }}>Team A</div>
<div style={{ fontSize: '12px', fontWeight: '400', backgroundColor: '#444444' }}>Organization</div>
</div>
<div style={{ marginRight: '4px' }}>
<FontAwesomeIcon icon={faChevronDown} />
</div>
</div>
</DropdownToggle>
<DropdownMenu>
<DropdownItem href="#">Team A</DropdownItem>
<DropdownItem href="#">Team B</DropdownItem>
<DropdownItem href="#">Team C</DropdownItem>
</DropdownMenu>
</Dropdown>
);
Loading