import { Layout, Playground, Attributes } from 'lib/components'
import { Snippet, Spacer, Code } from 'components'

export const meta = {
  title: 'Snippet',
  group: 'Others',
}

## Snippet

Display a snippet of copyable code for the command line.

<Playground
  desc="Basic usage."
  scope={{ Snippet }}
  code={`
<Snippet text="yarn add @geist-ui/core" width="300px" />
`}
/>

<Playground
  title="width"
  desc="Specify width manually."
  scope={{ Snippet }}
  code={`
<Snippet text="yarn add @geist-ui/core" width="100%" />
`}
/>

<Playground
  title="types"
  desc="Show different states with colors."
  scope={{ Snippet, Spacer }}
  code={`
<>
  <Snippet text="yarn add @geist-ui/core" type="dark" width="300px" />
  <Spacer />
  <Snippet text="yarn add @geist-ui/core" type="success" width="300px" />
  <Spacer />
  <Snippet text="yarn add @geist-ui/core" type="warning" width="300px" />
  <Spacer />
  <Snippet text="yarn add @geist-ui/core" type="error" width="300px" />
  <Spacer />
  <Snippet text="yarn add @geist-ui/core" type="secondary" width="300px" />
  <Spacer />
  <Snippet text="yarn add @geist-ui/core" type="lite" width="300px" />
</>
`}
/>

<Playground
  title="Multi Line"
  scope={{ Snippet }}
  code={`
<Snippet text={['cd project', 'now']} width="300px" />
`}
/>

<Playground
  title="without copy"
  desc="Hide icon for copy. (disable copy)"
  scope={{ Snippet }}
  code={`
<Snippet copy="prevent" text="yarn add @geist-ui/core" width="300px" />
`}
/>

<Playground
  title="custom symbol"
  scope={{ Snippet }}
  code={`
<Snippet symbol=">" text="yarn add @geist-ui/core" width="300px" />
`}
/>

<Playground
  title="custom toast"
  scope={{ Snippet }}
  code={`
<Snippet toastText="Code copied!" toastType="secondary" text="yarn add @geist-ui/core" width="300px" />
`}
/>

<Playground
  title="filled"
  scope={{ Snippet, Spacer }}
  code={`
<>
  <Snippet text="yarn add @geist-ui/core" type="success" filled width="300px" />
  <Spacer />
  <Snippet text="yarn add @geist-ui/core" type="warning" filled width="300px" />
  <Spacer />
  <Snippet text="yarn add @geist-ui/core" type="error" filled width="300px" />
  <Spacer />
  <Snippet text="yarn add @geist-ui/core" type="secondary" filled width="300px" />
</>
`}
/>

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

| Attribute     | Description             | Type                | Accepted values                  | Default                |
| ------------- | ----------------------- | ------------------- | -------------------------------- | ---------------------- |
| **text**      | code snippet            | `string` `string[]` | -                                | -                      |
| **type**      | snippet types           | `SnippetTypes`      | [SnippetTypes](#snippettypes)    | `default`              |
| **filled**    | filled style            | `boolean`           | -                                | `false`                |
| **width**     | set CSS string          | `string`            | -                                | `initial`              |
| **copy**      | function of copy button | `CopyTypes`         | [CopyTypes](#copytypes)          | `default`              |
| **symbol**    | symbol snippet          | `string`            | -                                | `$`                    |
| **toastText** | toast text              | `string`            | -                                | `Copied to clipboard!` |
| **toastType** | toast type              | `ToastTypes`        | [ToastTypes](#toasttypes)        | `success`              |
| ...           | native props            | `HTMLAttributes`    | `'id', 'name', 'className', ...` | -                      |

<Attributes.Title>SnippetTypes</Attributes.Title>

```ts
type SnippetTypes =
  | 'default'
  | 'secondary'
  | 'success'
  | 'warning'
  | 'error'
  | 'dark'
  | 'lite'
```

<Attributes.Title>CopyTypes</Attributes.Title>

```ts
type CopyTypes = 'default' | 'silent' | 'prevent'
```

<Attributes.Title>SnippetTypes</Attributes.Title>

```ts
type SnippetTypes = 'default' | 'secondary' | 'success' | 'warning' | 'error'
```

<Attributes.Title>ToastTypes</Attributes.Title>

```ts
type ToastTypes = 'default' | 'secondary' | 'success' | 'warning' | 'error'
```

</Attributes>

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