Skip to content

Commit

Permalink
feat(button): add icon prop (#156)
Browse files Browse the repository at this point in the history
* feat(button): add icon prop

* chore: update example for button's icon prop

* docs: update icon button doc
  • Loading branch information
wzc520pyfm committed Apr 3, 2023
1 parent 35f0ebf commit f36ed91
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/components/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Use `shadow` to show Button's shadow.

Use icons to add more meaning to Button. You can use icon alone to save some space, or use it with text.

Use the `icon` slots to add icon.
Use the `icon` slots or `icon` property to add icon.

<demo src="../example/button/icon.vue"></demo>

Expand Down Expand Up @@ -90,6 +90,7 @@ Use attribute `size` to set additional sizes with `xs`, `sm`,`md`,`lg`.
| to | `string` | `undefined` | Determine whether it's a link button. |
| rounded | `boolean` | `false` | Determine whether it's a round button. |
| loading | `boolean` | `false` | Determine whether it's loading. |
| icon | `string` | `undefined` | Icon's name. |
| disabled | `boolean` | `false` | Disable the button. |


Expand Down
4 changes: 4 additions & 0 deletions docs/example/button/icon.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div space-y-2>
<div fscw gap-2>
<o-button type="warning" icon="i-carbon-logo-github" />
<o-button type="secondary">
<template #icon>
<div i-carbon-share />
Expand All @@ -18,6 +19,9 @@
</o-button>
</div>
<div fscw gap-2>
<o-button type="warning" icon="i-carbon-logo-github">
Github
</o-button>
<o-button type="secondary">
<template #icon>
<div i-carbon-share />
Expand Down
4 changes: 4 additions & 0 deletions example/src/components/TheButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ const startLoading = () => {
<OButton size="lg" o="warning">
Large
</OButton>
<OButton size="lg" type="warning" icon="i-carbon-logo-github" />
<OButton size="lg" type="warning" icon="i-carbon-logo-github">
Github
</OButton>
<o-button :to="githubUrl" o="primary">
<template #icon>
<div i-carbon-logo-github />
Expand Down
4 changes: 2 additions & 2 deletions example/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<div py-4 space-y-5 min-h-800px>
<!-- <TheAvatar />
<TheIcon />
<TheButton />
<TheSwitch />
<TheCard />
<TheCheckbox />
Expand All @@ -12,10 +11,11 @@
<TheLink />
<TheAffix />
<TheRadio /> -->
<TheButton />
<TheMessage />
<TheEmpty />
<TheProgress />
<!-- <TheText />
<TheProgress />
<TheBacktop />
<ThePopup />
<TheRate />
Expand Down
6 changes: 4 additions & 2 deletions packages/components/button/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const typeLight = computed(() => props.type !== 'default' && props.light)
const defaultLight = computed(() => props.type === 'default' && props.light)
const defaultText = computed(() => props.type === 'default' && props.text)
const slots = useSlots()
const onlyIcon = computed(() => slots.icon && !slots.default)
const onlyIcon = computed(() => (slots.icon || props.icon) && !slots.default)
const binds = Object.assign({}, useAttrs(), props.to ? { href: props.to } : {})
</script>

Expand All @@ -34,7 +34,9 @@ const binds = Object.assign({}, useAttrs(), props.to ? { href: props.to } : {})
]"
>
<div v-if="loading" i-carbon-circle-dash animate-spin />
<slot v-else name="icon" />
<slot v-else name="icon">
<div v-if="icon" :class="icon" />
</slot>
<slot />
</component>
</template>
1 change: 1 addition & 0 deletions packages/components/button/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const buttonProps = {
},
disabled: Boolean,
loading: Boolean,
icon: String,
}

export type OButtonProps = ExtractPropTypes<typeof buttonProps>

0 comments on commit f36ed91

Please sign in to comment.