Skip to content

Commit

Permalink
Merge pull request #442 from dcos-labs/mp/feat/DCOS-61568-reset-butto…
Browse files Browse the repository at this point in the history
…n-docs

DCOS-61568: document and export ResetButton component
  • Loading branch information
mperrotti authored Dec 2, 2019
2 parents c379bb9 + 7b532e3 commit 347396c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 98 deletions.
3 changes: 3 additions & 0 deletions packages/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Use sentence-style capitalization (only the first word in a phrase and any prope

For Sets of Buttons, use specific labels, such as Save or Cancel, instead of using Yes and No. This is particularly helpful when the user is confirming an action.

## ResetButton
A `ResetButton` component is essentially an unstyled HTML `<button>` element. It can be used for an element that is semantically a button, but is not intended to look like a button.

## Feedback

Buttons should have hover, active, focus, disabled states.
Expand Down
42 changes: 4 additions & 38 deletions packages/button/components/ResetButton.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,15 @@
import * as React from "react";
import { css, cx } from "emotion";
import { cx } from "emotion";
import { buttonReset } from "../../shared/styles/styleUtils";

const pointerCursor = css`
cursor: pointer;
`;

const outlineNone = css`
&:focus {
outline: none;
}
`;

// Replicates default browser focus ring styles.
//
// The media query targets Webkit browsers, which can
// more accurately replicate the native focus ring style
const keyboardFocus = css`
&:focus > div {
outline-color: Highlight;
outline-width: thin;
@media (-webkit-min-device-pixel-ratio: 0) {
outline-color: -webkit-focus-ring-color;
outline-style: auto;
outline-width: unset;
}
}
`;
import { keyboardFocus, pointerCursor } from "../style";

const ResetButton = (props: React.HTMLAttributes<HTMLButtonElement>) => {
const { children, className, ...other } = props;
const classNames = cx(
buttonReset,
className,
outlineNone,
keyboardFocus,
pointerCursor
);
const classNames = cx(buttonReset, className, keyboardFocus, pointerCursor);

return (
<button className={classNames} {...other}>
<div className={outlineNone} tabIndex={-1}>
{children}
</div>
<div tabIndex={-1}>{children}</div>
</button>
);
};
Expand Down
19 changes: 19 additions & 0 deletions packages/button/stories/ResetButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from "react";
import { storiesOf } from "@storybook/react";
import { withReadme } from "storybook-readme";
import { ResetButton } from "../../";
import { Text } from "../../styleUtils/typography";

const readme = require("../README.md");

storiesOf("Buttons", module)
.addDecorator(withReadme([readme]))
.add("ResetButton", () => (
<div>
The{" "}
<Text tag="span" color="red">
<ResetButton>red text</ResetButton>
</Text>{" "}
is a button, but it is not styled like one
</div>
));
25 changes: 25 additions & 0 deletions packages/button/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,28 @@ export const getInverseMutedButtonStyles = (appearance: ButtonAppearances) => {
`
: inverseMutedButton;
};

export const pointerCursor = css`
cursor: pointer;
`;

// Replicates default browser focus ring styles.
//
// The media query targets Webkit browsers, which can
// more accurately replicate the native focus ring style
export const keyboardFocus = css`
> div:focus {
outline: none;
}
&:focus > div {
outline-color: Highlight;
outline-width: thin;
@media (-webkit-min-device-pixel-ratio: 0) {
outline-color: -webkit-focus-ring-color;
outline-style: auto;
outline-width: unset;
}
}
`;
3 changes: 2 additions & 1 deletion packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export {
SecondaryDropdownButton,
StandardDropdownButton,
SuccessDropdownButton,
DangerDropdownButton
DangerDropdownButton,
ResetButton
} from "./button";
export { ButtonCard, Card } from "./card";
export { LineChart } from "./chart";
Expand Down
Loading

0 comments on commit 347396c

Please sign in to comment.