Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 63370d3

Browse files
committed
feat(core): export chakra factory and add docs
1 parent 68cfcfe commit 63370d3

File tree

5 files changed

+150
-5
lines changed

5 files changed

+150
-5
lines changed

docs/components/button.md

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,113 @@
11
# Button
22

3-
> TODO
3+
The Button component is used to trigger an action or event, such as submitting a form, opening a dialog, canceling an action, or performing a delete operation.
4+
5+
## Import
6+
7+
```bash
8+
import { CButton, CButtonGroup } from "@chakra-ui/vue-next"
9+
```
10+
11+
- `CButton`: The button component with support for custom icons, spinners, etc.
12+
- `CButtonGroup`: Used to group buttons whose actions are related, with an option to flush them together.
13+
14+
## Usage
15+
```vue
16+
<c-button color-scheme="blue">Button</c-button>
17+
```
18+
19+
### Button sizes
20+
Use the `size` prop to change the size of the button. You can set the value to `xs`, `sm`, `md`, or `lg`.
21+
22+
```vue{1,4,7,10}
23+
<c-button color-scheme="teal" size="xs">
24+
Button
25+
</c-button>
26+
<c-button color-scheme="teal" size="sm">
27+
Button
28+
</c-button>
29+
<c-button color-scheme="teal" size="md">
30+
Button
31+
</c-button>
32+
<c-button color-scheme="teal" size="lg">
33+
Button
34+
</c-button>
35+
```
36+
37+
### Button variants
38+
39+
Use the `variant` prop to change the visual style of the Button. You can set the
40+
value to `solid`, `ghost`, `outline`, or `link`.
41+
42+
```vue{1,4,7,10}
43+
<c-button color-scheme="teal" variant="solid">
44+
Button
45+
</c-button>
46+
<c-button color-scheme="teal" variant="outline">
47+
Button
48+
</c-button>
49+
<c-button color-scheme="teal" variant="ghost">
50+
Button
51+
</c-button>
52+
<c-button color-scheme="teal" variant="link">
53+
Button
54+
</c-button>
55+
```
56+
57+
### Button with icon
58+
59+
You can add left and right icons to the Button component using the `left-icon`
60+
and `right-icon` props respectively.
61+
62+
::: warning TODO
63+
TODO: Link to icon documentation
64+
65+
:::
66+
67+
### Button loading state
68+
69+
Pass the `is-loading` prop to show its loading state. By default, the button will
70+
show a spinner and leave the button's width unchanged.
71+
72+
You can also pass the `loading-text` prop to show a spinner and the loading text.
73+
```vue
74+
<c-button is-loading color-scheme="teal" variant="solid">
75+
Email
76+
</c-button>
77+
<c-button is-loading loading-text="Submitting" color-scheme="teal" variant="outline">
78+
Submit
79+
</c-button>
80+
```
81+
82+
### Grouping Buttons
83+
84+
You can use the `CStack` or `CButtonGroup` component to group buttons. When you
85+
use the `CButtonGroup` component, it allows you to:
86+
87+
- Set the `size` and `variant` of all buttons within it.
88+
- Add `spacing` between the buttons.
89+
- Flush the buttons together by removing the border radius of the its children
90+
as needed.
91+
92+
```vue
93+
<c-button-group size="sm" is-attached variant="outline">
94+
<c-button mr="-px">Save</c-button>
95+
<c-icon-button aria-label="Add to friends" icon="plus" />
96+
</c-button-group>
97+
```
98+
99+
## Accessibility
100+
101+
- `CButton` has `role` of `button`.
102+
- When `CButton` has focus, <kbd>Space</kbd> or <kbd>Enter</kbd> activates it.
103+
104+
## Composition
105+
106+
Theming props passed into the `CButton` component (e.g. `variant`, `colorScheme`, etc.) are converted to style props. This means you can override any style of the `CButton` via type style props.
107+
108+
## Props
109+
110+
### Button Props
111+
112+
`CButton` composes the `CBox` component, so you can pass all its props.
113+
These are props specific to the `CButton` component:
Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
<template>
22
<chakra.p mt="3" font-weight="bold">IconButton</chakra.p>
3-
<c-icon-button icon="star" mr="3" size="xs" color-scheme="teal" />
4-
<c-icon-button icon="star" mr="3" size="sm" color-scheme="teal" />
5-
<c-icon-button icon="star" mr="3" size="md" color-scheme="teal" />
6-
<c-icon-button icon="star" mr="3" size="lg" color-scheme="teal" />
3+
<c-icon-button
4+
icon="star"
5+
aria-label="Favourite album"
6+
mr="3"
7+
size="xs"
8+
color-scheme="teal"
9+
/>
10+
<c-icon-button
11+
icon="star"
12+
aria-label="Favourite album"
13+
mr="3"
14+
size="sm"
15+
color-scheme="teal"
16+
/>
17+
<c-icon-button
18+
icon="star"
19+
aria-label="Favourite album"
20+
mr="3"
21+
size="md"
22+
color-scheme="teal"
23+
/>
24+
<c-icon-button
25+
icon="star"
26+
aria-label="Favourite album"
27+
mr="3"
28+
size="lg"
29+
color-scheme="teal"
30+
/>
731
</template>

packages/c-button/src/icon-button.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const CIconButton = defineComponent({
2222
name: 'CIconButton',
2323
props: IconButtonProps,
2424
setup(props, { attrs }) {
25+
if (!props.ariaLabel) {
26+
console.error(
27+
`chakra-ui: The \`aria-label\` prop is required for the <c-icon-button />`
28+
)
29+
}
2530
return () =>
2631
h(
2732
CButton,

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"watch:types": "cross-env tsc --emitDeclarationOnly --declaration --declarationDir dist/types --watch"
2424
},
2525
"dependencies": {
26+
"@chakra-ui/vue-system": "*",
2627
"@chakra-ui/vue-theme": "*",
2728
"@chakra-ui/vue-utils": "*",
2829
"@chakra-ui/c-accordion": "*",

packages/core/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Plugin } from 'vue'
22
import defaultTheme, { ColorMode } from '@chakra-ui/vue-theme'
3+
import { chakra } from '@chakra-ui/vue-system'
34
import internalIcons from './icon.internals'
45
import { extendTheme, ThemeOverride } from './extend-theme'
56
import { MergedIcons, parseIcons } from './parse-icons'
@@ -50,7 +51,11 @@ export interface ThemeProviderProps extends ThemeOverride {}
5051
export default ChakraUIVuePlugin
5152
export { extendTheme }
5253

54+
// Export chakra factory function
55+
export { chakra }
56+
5357
// Component exports
58+
export const CBox = chakra.div
5459

5560
export * from '@chakra-ui/c-accordion'
5661
export * from '@chakra-ui/c-alert'

0 commit comments

Comments
 (0)