-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(button): ✨ add react aria buttons & interactions (#9)
* feat(button): ✨ add react aria buttons * feat(components): ✨ add focus, button & link * docs(button): 📝 better storybook docs for button * feat(calendar): ✨ start calendar experiment * refactor: ♻️ remove datepicker experiments * refactor(hooks): 👌 update code after code review * refactor(type): ♻️ change type for button state aria
- Loading branch information
1 parent
9feb564
commit b61e990
Showing
26 changed files
with
1,466 additions
and
363 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
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,31 @@ | ||
import * as React from "react"; | ||
import { useForkRef } from "reakit-utils"; | ||
import { useLink, AriaLinkOptions } from "@react-aria/link"; | ||
import { BoxHTMLProps, useBox } from "reakit"; | ||
import { mergeProps } from "@react-aria/utils"; | ||
import { INTERACTION_KEYS } from "../interactions/__keys"; | ||
import { createComponent, createHook } from "reakit-system"; | ||
|
||
export const useAriaLink = createHook<AriaLinkOptions, BoxHTMLProps>({ | ||
name: "AriaLink", | ||
keys: INTERACTION_KEYS, | ||
compose: [useBox], | ||
|
||
useProps(options, { ref: htmlRef, ...htmlProps }) { | ||
const props = { ...options, ...htmlProps }; | ||
const ref = React.useRef<HTMLElement>(null); | ||
|
||
const { linkProps } = useLink(props, ref); | ||
|
||
return mergeProps(htmlProps, { | ||
...linkProps, | ||
ref: useForkRef(ref, htmlRef), | ||
}); | ||
}, | ||
}); | ||
|
||
export const AriaLink = createComponent({ | ||
as: "a", | ||
memo: true, | ||
useHook: useAriaLink, | ||
}); |
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 @@ | ||
export * from "./AriaLink"; |
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,58 @@ | ||
import React from "react"; | ||
import { Meta } from "@storybook/react"; | ||
import { AriaLink } from "../index"; | ||
|
||
export default { | ||
title: "Component/Link", | ||
} as Meta; | ||
|
||
export const ReactAriaLink = () => { | ||
return ( | ||
<AriaLink | ||
href="https://adobe.com" | ||
target="_blank" | ||
style={{ | ||
color: "blue", | ||
textDecoration: "underline", | ||
cursor: "pointer", | ||
}} | ||
> | ||
Adobe | ||
</AriaLink> | ||
); | ||
}; | ||
|
||
export const ReactAriaCustomLink = () => { | ||
return ( | ||
<AriaLink | ||
as="span" | ||
elementType="span" | ||
style={{ | ||
color: "blue", | ||
textDecoration: "underline", | ||
cursor: "pointer", | ||
}} | ||
onPress={() => alert("Pressed link")} | ||
> | ||
Custom | ||
</AriaLink> | ||
); | ||
}; | ||
|
||
export const ReactAriaDisabledLink = () => { | ||
return ( | ||
<AriaLink | ||
href="https://adobe.com" | ||
target="_blank" | ||
style={{ | ||
color: "blue", | ||
textDecoration: "underline", | ||
cursor: "pointer", | ||
}} | ||
onPress={() => alert("Pressed link")} | ||
isDisabled | ||
> | ||
Adobe | ||
</AriaLink> | ||
); | ||
}; |
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,32 @@ | ||
import * as React from "react"; | ||
import { useForkRef } from "reakit-utils"; | ||
import { BoxHTMLProps, useBox } from "reakit"; | ||
import { useButton } from "@react-aria/button"; | ||
import { mergeProps } from "@react-aria/utils"; | ||
import { AriaButtonProps } from "@react-types/button"; | ||
import { INTERACTION_KEYS } from "../interactions/__keys"; | ||
import { createComponent, createHook } from "reakit-system"; | ||
|
||
export const useAriaButton = createHook<AriaButtonProps, BoxHTMLProps>({ | ||
name: "AriaButton", | ||
keys: INTERACTION_KEYS, | ||
compose: [useBox], | ||
|
||
useProps(options, { ref: htmlRef, ...htmlProps }) { | ||
const props = { ...options, ...htmlProps } as AriaButtonProps; | ||
const ref = React.useRef<HTMLElement>(null); | ||
|
||
const { buttonProps } = useButton(props, ref); | ||
|
||
return mergeProps(htmlProps, { | ||
...buttonProps, | ||
ref: useForkRef(ref, htmlRef), | ||
}); | ||
}, | ||
}); | ||
|
||
export const AriaButton = createComponent({ | ||
as: "button", | ||
memo: true, | ||
useHook: useAriaButton, | ||
}); |
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,40 @@ | ||
import * as React from "react"; | ||
import { useForkRef } from "reakit-utils"; | ||
import { BoxHTMLProps, useBox } from "reakit"; | ||
import { mergeProps } from "@react-aria/utils"; | ||
import { ToggleState } from "@react-stately/toggle"; | ||
import { useToggleButton } from "@react-aria/button"; | ||
import { INTERACTION_KEYS } from "../interactions/__keys"; | ||
import { createComponent, createHook } from "reakit-system"; | ||
import { AriaToggleButtonProps } from "@react-types/button"; | ||
|
||
type useAriaToggleButtonOptions = AriaToggleButtonProps & ToggleState; | ||
|
||
export const useAriaToggleButton = createHook< | ||
useAriaToggleButtonOptions, | ||
BoxHTMLProps | ||
>({ | ||
name: "AriaToggleButton", | ||
keys: [...INTERACTION_KEYS, "isSelected", "setSelected", "toggle"], | ||
compose: [useBox], | ||
|
||
useProps(options, { ref: htmlRef, ...htmlProps }) { | ||
const { isSelected, setSelected, toggle, ...restOptions } = options; | ||
const props = { ...restOptions, ...htmlProps } as AriaToggleButtonProps; | ||
const state = { isSelected, setSelected, toggle }; | ||
const ref = React.useRef<HTMLElement>(null); | ||
|
||
const { buttonProps } = useToggleButton(props, state, ref); | ||
|
||
return mergeProps(htmlProps, { | ||
...buttonProps, | ||
ref: useForkRef(ref, htmlRef), | ||
}); | ||
}, | ||
}); | ||
|
||
export const AriaToggleButton = createComponent({ | ||
as: "button", | ||
memo: true, | ||
useHook: useAriaToggleButton, | ||
}); |
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,3 @@ | ||
export { Button, useButton } from "reakit/Button"; | ||
export * from "./AriaButton"; | ||
export * from "./AriaToggleButton"; |
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,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, | ||
}; |
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,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, | ||
}; |
Oops, something went wrong.