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

feat(button): ✨ add react aria buttons #9

Merged
merged 8 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
docs(button): 📝 better storybook docs for button
  • Loading branch information
navin-moorthy committed Aug 26, 2020
commit b5bd79d3164f5005a67e4ca66ce9c942e9c4e7e9
1 change: 1 addition & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
layout: "centered",
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@react-aria/utils": "^3.2.0",
"@react-stately/toggle": "^3.2.0",
"@types/lodash.debounce": "^4.0.6",
"emotion": "^10.0.27",
"lodash.debounce": "^4.0.8",
"reakit": "^1.2.3",
"reakit-system": "^0.14.3",
Expand Down
79 changes: 0 additions & 79 deletions src/AriaButton/stories/Button.stories.tsx

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions src/button/stories/AriaButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import { Meta, Story } from "@storybook/react";
import { ReactAriaButton, ReactAriaButtonProps } from "./Buttons";

export default {
title: "Component/Buttons/ReactAriaButton",
component: ReactAriaButton,
} as Meta;

const Template: Story<ReactAriaButtonProps> = args => (
<ReactAriaButton {...args} />
);

export const Default = Template.bind({});
Default.args = {};

export const LinkButton = Template.bind({});
LinkButton.args = {
as: "a",
elementType: "a",
href: "https://reakit.io/docs/button/",
target: "_blank",
rel: "noreferrer noopener",
};

export const SpanButton = Template.bind({});
SpanButton.args = {
as: "span",
elementType: "span",
};

export const AutoFocus = Template.bind({});
AutoFocus.args = {
autoFocus: true,
};

export const Disabled = Template.bind({});
Disabled.args = {
isDisabled: true,
};
40 changes: 40 additions & 0 deletions src/button/stories/AriaToggleButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import { Meta, Story } from "@storybook/react";
import { ReactAriaToggleButton, ReactAriaButtonProps } from "./Buttons";

export default {
title: "Component/Buttons/ReactAriaToggleButton",
component: ReactAriaToggleButton,
} as Meta;

const Template: Story<ReactAriaButtonProps> = args => (
<ReactAriaToggleButton {...args} />
);

export const Default = Template.bind({});
Default.args = {};

export const LinkButton = Template.bind({});
LinkButton.args = {
as: "a",
elementType: "a",
href: "https://reakit.io/docs/button/",
target: "_blank",
rel: "noreferrer noopener",
};

export const SpanButton = Template.bind({});
SpanButton.args = {
as: "span",
elementType: "span",
};

export const AutoFocus = Template.bind({});
AutoFocus.args = {
autoFocus: true,
};

export const Disabled = Template.bind({});
Disabled.args = {
isDisabled: true,
};
155 changes: 155 additions & 0 deletions src/button/stories/Buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import React, { JSXElementConstructor, useState } from "react";
import { Button, AriaButton, AriaToggleButton } from "../index";
import { useToggleState } from "@react-stately/toggle";

export interface ButtonProps {
/**
* Button contents
* @default Button
*/
label: string;
/**
* The HTML element or React element used to render the button, e.g. 'div', 'a', or `RouterLink`.
* @default 'button'
*/
as?: "button" | undefined;
/** A URL to link to if elementType="a". */
href?: string;
/** The target window for the link. */
target?: string;
/** The relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel). */
rel?: string;
/**
* Is button disabled
* @default false
*/
disabled?: boolean;
/**
* Is button focusable
* @default false
*/
focusable?: boolean;
/**
* Optional click handler
*/
onClick?: () => void;
}

export const ReakitButton: React.FC<ButtonProps> = ({
label = "Button",
...props
}) => {
return (
<Button
{...props}
style={{
background: "green",
color: "white",
padding: 10,
cursor: "pointer",
userSelect: "none",
WebkitUserSelect: "none",
border: "none",
}}
>
{label}
</Button>
);
};

export interface ReactAriaButtonProps {
/**
* Button contents
*
* @default Button
*/
label: string;
/**
* The behavior of the button when used in an HTML form.
* @default 'button'
*/
type?: "button" | "submit" | "reset";
/** Whether the button is disabled. */
isDisabled?: boolean;
/** Whether the element should receive focus on render. */
autoFocus?: boolean;
/**
* The HTML element or React element used to render the button, e.g. 'div', 'a', or `RouterLink`.
* @default 'button'
*/
as?: "button" | undefined;
/**
* The HTML element or React element used to render the button, e.g. 'div', 'a', or `RouterLink`.
* @default 'button'
*/
elementType?: string | JSXElementConstructor<any>;

/** A URL to link to if elementType="a". */
href?: string;
/** The target window for the link. */
target?: string;
/** The relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel). */
rel?: string;
/**
* Optional click handler
*/
onPress?: () => void;
}

export const ReactAriaButton: React.FC<ReactAriaButtonProps> = ({
label,
...props
}) => {
const [isPressed, setIsPressed] = useState(false);

return (
<AriaButton
{...props}
onPressChange={setIsPressed}
style={{
background: isPressed ? "darkgreen" : "green",
color: "white",
padding: 10,
cursor: "pointer",
userSelect: "none",
WebkitUserSelect: "none",
border: "none",
}}
>
button
</AriaButton>
);
};

export const ReactAriaToggleButton: React.FC<ReactAriaButtonProps> = ({
label,
...props
}) => {
const state = useToggleState();
const [isPressed, setIsPressed] = useState(false);

return (
<AriaToggleButton
{...state}
{...props}
onPressChange={setIsPressed}
style={{
background: isPressed
? state.isSelected
? "darkblue"
: "darkgreen"
: state.isSelected
? "blue"
: "green",
color: "white",
padding: 10,
cursor: "pointer",
userSelect: "none",
WebkitUserSelect: "none",
border: "none",
}}
>
{label}
</AriaToggleButton>
);
};
37 changes: 37 additions & 0 deletions src/button/stories/ReakitButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from "react";
import { Meta, Story } from "@storybook/react";
import { ReakitButton, ButtonProps } from "./Buttons";

export default {
title: "Component/Buttons/ReakitButton",
component: ReakitButton,
} as Meta;

const Template: Story<ButtonProps> = args => <ReakitButton {...args} />;

export const Default = Template.bind({});

export const LinkButton = Template.bind({});
LinkButton.args = {
as: "a",
href: "https://reakit.io/docs/button/",
target: "_blank",
rel: "noreferrer noopener",
};

export const SpanButton = Template.bind({});
SpanButton.args = {
as: "span",
};

export const Disabled = Template.bind({});
Disabled.args = {
disabled: true,
focusable: false,
};

export const Focusable = Template.bind({});
Focusable.args = {
disabled: true,
focusable: true,
};
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./accordion";
export * from "./button";
export * from "./interactions";
export * from "./select";
export * from "./slider";
export * from "./AriaButton";
export * from "./link";
2 changes: 1 addition & 1 deletion src/slider/stories/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const sliderThumbStyle: CSSProperties = {

export const sliderHorizontalStyle: CSSProperties = {
...sliderStyle,
width: "100%",
width: "200px",
};

export const sliderHorizontalTrackStyle: CSSProperties = {
Expand Down
Loading