import { Layout, Playground, Attributes } from 'lib/components'
import { Button, Spacer, Grid, Code } from 'components'
import Settings from '@geist-ui/icons/settings'
import UserX from '@geist-ui/icons/userX'
import Power from '@geist-ui/icons/power'

export const meta = {
  title: 'Button',
  group: 'General',
}

## Button

Used to trigger an operation.

<Playground
  title="Basic"
  desc="The basic `Button` contains an animation effect."
  scope={{ Button }}
  code={`
<Button>Action</Button>
`}
/>

<Playground
  title="Loading"
  desc="Show running status."
  scope={{ Button, Spacer }}
  code={`
<>
  <Button loading>Action</Button>
  <Spacer h={.5} />
  <Button loading scale={0.75}>Action</Button>
  <Spacer h={.5} />
  <Button loading auto type="success" scale={2/3}>Action</Button>
</>
`}
/>

<Playground
  title="Disabled"
  desc="Do not respond to any action."
  scope={{ Button }}
  code={`
<Button disabled>Action</Button>
`}
/>

<Playground
  title="Shadow"
  desc="The shadow highlights the level of the button."
  scope={{ Button }}
  code={`
<Button shadow type="secondary">Shadow</Button>
`}
/>

<Playground
  title="Types"
  desc="Different state."
  scope={{ Button, Spacer, Grid }}
  code={`
<Grid.Container gap={1.5}>
  <Grid><Button auto type="secondary">Secondary</Button></Grid>
  <Grid><Button auto type="success">Success</Button></Grid>
  <Grid><Button auto type="warning">Warning</Button></Grid>
  <Grid><Button auto type="error">Error</Button></Grid>
  <Grid><Button auto type="abort">Abort</Button></Grid>
  <Grid><Button auto type="secondary-light">Secondary Light</Button></Grid>
  <Grid><Button auto type="success-light">Success Light</Button></Grid>
  <Grid><Button auto type="warning-light">Warning Light</Button></Grid>
  <Grid><Button auto type="error-light">Error Light</Button></Grid>
</Grid.Container>
`}
/>

<Playground
  title="GHOST"
  desc="The opposite color."
  scope={{ Button, Grid }}
  code={`
<Grid.Container gap={1.5}>
  <Grid><Button type="secondary" ghost auto scale={0.7}>Secondary</Button></Grid>
  <Grid><Button type="success" ghost auto scale={0.7}>Success</Button></Grid>
  <Grid><Button type="warning" ghost auto scale={0.7}>Warning</Button></Grid>
  <Grid><Button type="error" ghost auto scale={0.7}>Error</Button></Grid>
</Grid.Container>
`}
/>

<Playground
  title="Scale"
  desc="Buttons of different sizes."
  scope={{ Button, Grid }}
  code={`
<Grid.Container gap={1.5}>
  <Grid><Button auto scale={0.25}>0.25</Button></Grid>
  <Grid><Button auto scale={0.35}>0.35</Button></Grid>
  <Grid><Button auto scale={1/2}>1 / 2</Button></Grid>
  <Grid><Button auto scale={0.75}>0.75</Button></Grid>
  <Grid><Button auto padding={0}>NoPadding</Button></Grid>
  <Grid><Button auto font={0.25}>Small Font</Button></Grid>
  <Grid><Button auto pl={0} ml="25px">Offset</Button></Grid>
  <Grid xs={12}><Button width="100%">Full Width</Button></Grid>
  <Grid xs={12}>
    <Button auto width="30%" mx="5px">proportion</Button>
    <Button auto width="30%" mx="5px">proportion</Button>
    <Button auto width="30%" mx="5px">proportion</Button>
  </Grid>
</Grid.Container>
`}
/>

<Playground
  title="With Icons"
  desc="The `color` and `size` of the icon will be set automatically."
  scope={{ Button, Spacer, Settings, UserX, Power }}
  code={`
<>
  <Button iconRight={<Power />} auto scale={2/3} />
  <Spacer w={.5} inline />
  <Button iconRight={<Power />} auto scale={2/3} px={0.6} />
  <Spacer h={.5} />
  <Button icon={<Settings />} auto>Action</Button>
  <Spacer h={.5} />
  <Button icon={<Settings />} type="success" scale={0.85}>Success</Button>
  <Spacer h={.5} />
  <Button icon={<Settings />} type="secondary">Success</Button>
  <Spacer h={.5} />
  <Button icon={<UserX />} type="error" ghost>Remove User</Button>
  <Spacer h={.5} />
  <Button icon={<UserX />} disabled>Remove User</Button>
</>
`}
/>

<Attributes edit="/pages/en-us/components/button.mdx">
<Attributes.Title>Button.Props</Attributes.Title>

| Attribute     | Description                               | Type                                            | Accepted values             | Default   |
| ------------- | ----------------------------------------- | ----------------------------------------------- | --------------------------- | --------- |
| **type**      | button type                               | `ButtonTypes`                                   | [ButtonTypes](#buttontypes) | `default` |
| **ghost**     | the opposite color                        | `boolean`                                       | -                           | `false`   |
| **loading**   | display loading indicator                 | `boolean`                                       | -                           | `false`   |
| **shadow**    | display shadow                            | `boolean`                                       | -                           | `false`   |
| **auto**      | autoscale width                           | `boolean`                                       | -                           | `false`   |
| **effect**    | display animation                         | `boolean`                                       | -                           | `true`    |
| **disabled**  | disable button                            | `boolean`                                       | -                           | `false`   |
| **onClick**   | click handler                             | `MouseEventHandler`                             | -                           | -         |
| **icon**      | show icon in button                       | `ReactNode`                                     | -                           | -         |
| **iconRight** | show icon on the other side of the button | `ReactNode`                                     | -                           | -         |
| **htmlType**  | native type of button element             | `ButtonHTMLAttributes.type`                     | -                           | `button`  |
| **ref**       | forwardRef                                | <Code>Ref<HTMLButtonElement &#124; null></Code> | -                           | -         |
| ...           | native props                              | `ButtonHTMLAttributes`                          | `'id', 'className', ...`    | -         |

<Attributes.Title>ButtonTypes</Attributes.Title>

```ts
type ButtonTypes =
  | 'default'
  | 'secondary'
  | 'success'
  | 'warning'
  | 'error'
  | 'abort'
  | 'secondary-light'
  | 'success-light'
  | 'warning-light'
  | 'error-light'
```

</Attributes>

export default ({ children }) => <Layout meta={meta}>{children}</Layout>
