-
Notifications
You must be signed in to change notification settings - Fork 41
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 #399 from dcos-labs/mp/feat/DCOS-57983-add-toggle-…
…button DCOS-57983: adds ToggleBox and related component
- Loading branch information
Showing
29 changed files
with
2,560 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,62 @@ | ||
import Card, { CardProps } from "./Card"; | ||
import { | ||
buttonCard, | ||
buttonCardActive, | ||
buttonCardDisabled, | ||
buttonCardDisabledActive, | ||
buttonCardFocused, | ||
buttonCardFocusedActive | ||
} from "../style"; | ||
import { cx } from "emotion"; | ||
|
||
export interface ButtonCardProps extends CardProps { | ||
/** | ||
* Whether the component should look and act like a disabled element | ||
*/ | ||
disabled?: boolean; | ||
/** | ||
* Whether the component is in the "on" state | ||
*/ | ||
isActive?: boolean; | ||
/** | ||
* Whether the component is controlled by a checkbox or radio input | ||
*/ | ||
isInput?: boolean; | ||
/** | ||
* Whether the component's child input has focus | ||
*/ | ||
hasFocus?: boolean; | ||
} | ||
|
||
class ButtonCard extends Card<ButtonCardProps, {}> { | ||
public render() { | ||
const { isActive, isInput, disabled, hasFocus, ...other } = this.props; | ||
const tabIndex = disabled ? -1 : 0; | ||
const buttonProps = !isInput | ||
? { | ||
tabIndex, | ||
role: "button", | ||
"aria-disabled": disabled, | ||
"aria-pressed": isActive | ||
} | ||
: {}; | ||
const buttonCardProps = { | ||
...{ "data-cy": "buttonCard" }, | ||
...buttonProps, | ||
...other | ||
}; | ||
|
||
return this.getCardElement( | ||
buttonCardProps, | ||
cx(buttonCard, { | ||
[buttonCardActive]: isActive, | ||
[buttonCardDisabled]: disabled, | ||
[buttonCardDisabledActive]: disabled && isActive, | ||
[buttonCardFocused]: hasFocus, | ||
[buttonCardFocusedActive]: hasFocus && isActive | ||
}) | ||
); | ||
} | ||
} | ||
|
||
export default ButtonCard; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as Card } from "./components/Card"; | ||
export { default as ButtonCard } from "./components/ButtonCard"; |
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,26 @@ | ||
import * as React from "react"; | ||
import { storiesOf } from "@storybook/react"; | ||
import { withReadme } from "storybook-readme"; | ||
import { action } from "@storybook/addon-actions"; | ||
import ButtonCard from "../components/ButtonCard"; | ||
import { SpacingBox } from "../../styleUtils/modifiers"; | ||
|
||
const readme = require("../README.md"); | ||
|
||
storiesOf("Card/ButtonCard", module) | ||
.addDecorator(withReadme([readme])) | ||
.add("default", () => <ButtonCard>default</ButtonCard>) | ||
.add("active", () => <ButtonCard isActive={true}>isActive</ButtonCard>) | ||
.add("disabled", () => ( | ||
<React.Fragment> | ||
<SpacingBox side="bottom"> | ||
<ButtonCard disabled={true}>disabled</ButtonCard> | ||
</SpacingBox> | ||
<ButtonCard disabled={true} isActive={true}> | ||
disabled + isActive | ||
</ButtonCard> | ||
</React.Fragment> | ||
)) | ||
.add("with onClick", () => ( | ||
<ButtonCard onClick={action("button clicked")}>default</ButtonCard> | ||
)); |
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 |
---|---|---|
@@ -1,13 +1,84 @@ | ||
import { css } from "emotion"; | ||
import { border, borderRadius } from "../shared/styles/styleUtils/index"; | ||
import { themeBgPrimary } from "../design-tokens/build/js/designTokens"; | ||
import { borderRadius } from "../shared/styles/styleUtils/index"; | ||
import { | ||
themeBgPrimary, | ||
themeBorder, | ||
themeBrandPrimary, | ||
themeBgDisabled, | ||
themeTextColorDisabled, | ||
themeBgHover | ||
} from "../design-tokens/build/js/designTokens"; | ||
|
||
export const style = css` | ||
export const cardBase = css` | ||
background-color: ${themeBgPrimary}; | ||
${border("all")}; | ||
box-shadow: 0 0 0 1px ${themeBorder}; | ||
${borderRadius("default")}; | ||
> div { | ||
height: 100%; | ||
} | ||
`; | ||
|
||
const buttonCardFocusStyles = ` | ||
box-shadow: 0 0 0 1px ${themeBrandPrimary}; | ||
outline: 0; | ||
`; | ||
|
||
const buttonCardActiveStyles = ` | ||
box-shadow: 0 0 0 2px ${themeBrandPrimary}; | ||
`; | ||
|
||
const buttonCardFocusedActiveStyles = `background-color: ${themeBgHover};`; | ||
|
||
export const buttonCard = css` | ||
cursor: pointer; | ||
&:hover, | ||
&:focus { | ||
${buttonCardFocusStyles}; | ||
} | ||
&:active { | ||
${buttonCardActiveStyles}; | ||
} | ||
`; | ||
|
||
export const buttonCardActive = css` | ||
&, | ||
&:hover, | ||
&:focus { | ||
${buttonCardActiveStyles}; | ||
} | ||
&:focus { | ||
${buttonCardFocusedActiveStyles}; | ||
} | ||
`; | ||
|
||
export const buttonCardFocused = css` | ||
${buttonCardFocusStyles}; | ||
`; | ||
|
||
export const buttonCardDisabled = css` | ||
background-color: ${themeBgDisabled}; | ||
color: ${themeTextColorDisabled}; | ||
cursor: auto; | ||
&, | ||
&:hover, | ||
&:focus { | ||
box-shadow: 0 0 0 0 transparent; | ||
} | ||
`; | ||
|
||
export const buttonCardDisabledActive = css` | ||
&, | ||
&:hover, | ||
&:focus { | ||
box-shadow: 0 0 0 2px ${themeBorder}; | ||
} | ||
`; | ||
|
||
export const buttonCardFocusedActive = css` | ||
${buttonCardFocusedActiveStyles}; | ||
`; |
Oops, something went wrong.