Skip to content

Commit

Permalink
feat(kbutton): add appearance="none" to button (#2469)
Browse files Browse the repository at this point in the history
* feat(kbutton): add appearance="none" to button

* docs(ktable): add docs

* fix(kbutton): add more basestyle, remove href for disabled link

* docs(ktable): refine note

* fix(kbutton): add style when `icon` is set

* docs(kbutton): improve docs, remove icon+text example from sandbox
  • Loading branch information
Justineo authored Oct 23, 2024
1 parent ada18de commit 30fb03a
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .stylelintrc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export default {
rules: {
// Disallow relative font units since we don't know the base font size in other apps
'unit-disallowed-list': ['rem', 'em'],
'order/properties-alphabetical-order': true,
'order/properties-order': [
['all'],
{ 'unspecified': 'bottomAlphabetical' },
],
'@kong/design-tokens/use-proper-token': true,
'@stylistic/indentation': [2, { baseIndentLevel: 0 }],
// Only allow @kong/design-tokens or `--kong-ui-*` CSS custom properties
Expand Down
11 changes: 10 additions & 1 deletion docs/components/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,34 @@ and configuration options.

### appearance

The Button component can take 1 of 4 appearance values:
The Button component can take 1 of 5 appearance values:

- `primary`
- `secondary`
- `tertiary`
- `danger`
- `none`

:::tip NOTE
Use `appearance="none"` to get an unstyled button, making it easier to customize from scratch. This removes the built-in styling but retains the button's functionality.

When `appearance="none"` is set, the `size` prop only works if `icon` is `true`; otherwise, `size` has no effect.
:::

<div class="spacing-container">
<KButton appearance="primary">Primary</KButton>
<KButton appearance="secondary">Secondary</KButton>
<KButton appearance="tertiary">Tertiary</KButton>
<KButton appearance="danger">Danger</KButton>
<KButton appearance="none">None</KButton>
</div>

```html
<KButton appearance="primary">Primary</KButton>
<KButton appearance="secondary">Secondary</KButton>
<KButton appearance="tertiary">Tertiary</KButton>
<KButton appearance="danger">Danger</KButton>
<KButton appearance="none">None</KButton>
```

### size
Expand Down
1 change: 1 addition & 0 deletions docs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default defineConfig({
css: {
preprocessorOptions: {
scss: {
api: 'modern',
// Inject the @kong/design-tokens SCSS variables, kongponents variables and mixins to make them available for all components.
// This is not needed in host applications.
additionalData: `
Expand Down
113 changes: 112 additions & 1 deletion sandbox/pages/SandboxButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
title="appearance"
>
<template #description>
KButton component takes 1 of 4 appearance values:
KButton component takes 1 of 5 appearance values:
<ul>
<li>
<em>primary</em> - default value
Expand All @@ -27,6 +27,9 @@
<li>
<em>danger</em>
</li>
<li>
<em>none</em>
</li>
</ul>
</template>
<div class="horizontal-spacing">
Expand All @@ -51,6 +54,12 @@
>
Danger
</KButton>
<KButton
appearance="none"
@click="test"
>
None
</KButton>
</div>
<div class="horizontal-spacing">
<KButton
Expand Down Expand Up @@ -80,12 +89,20 @@
>
Disabled
</KButton>
<KButton
appearance="none"
disabled
@click="test"
>
Disabled
</KButton>
</div>
</SandboxSectionComponent>
<SandboxSectionComponent
description="Here we pass an invalid value to the appearance prop (see the error in the console) which the KButton handles by falling back to primary appearance."
title="invalid value"
>
<!-- @vue-expect-error -->
<KButton appearance="outline">
Still Primary
</KButton>
Expand Down Expand Up @@ -188,6 +205,13 @@
>
Danger
</KButton>
<KButton
appearance="none"
target="_blank"
to="https://kongponents.konghq.com/"
>
None
</KButton>
<KButton
disabled
target="_blank"
Expand Down Expand Up @@ -229,6 +253,13 @@
>
Danger
</KButton>
<KButton
appearance="none"
target="_blank"
:to="{ name: 'home' }"
>
None
</KButton>
<KButton
disabled
target="_blank"
Expand Down Expand Up @@ -347,6 +378,13 @@
Danger
<ChevronDownIcon />
</KButton>
<KButton
appearance="none"
size="large"
>
None
<ChevronDownIcon />
</KButton>
</div>
<div class="horizontal-spacing">
<KButton>
Expand All @@ -365,6 +403,10 @@
Danger
<ChevronDownIcon />
</KButton>
<KButton appearance="none">
None
<ChevronDownIcon />
</KButton>
</div>
<div class="horizontal-spacing">
<KButton size="small">
Expand Down Expand Up @@ -392,6 +434,13 @@
Danger
<ChevronDownIcon />
</KButton>
<KButton
appearance="none"
size="small"
>
None
<ChevronDownIcon />
</KButton>
</div>
</SandboxSectionComponent>

Expand Down Expand Up @@ -429,6 +478,13 @@
>
<DisabledIcon />
</KButton>
<KButton
appearance="none"
icon
size="large"
>
<AddCircleIcon />
</KButton>
</div>
<div class="horizontal-spacing">
<KButton icon>
Expand All @@ -452,6 +508,12 @@
>
<DisabledIcon />
</KButton>
<KButton
appearance="none"
icon
>
<AddCircleIcon />
</KButton>
</div>
<div class="horizontal-spacing">
<KButton
Expand Down Expand Up @@ -481,6 +543,36 @@
>
<DisabledIcon />
</KButton>
<KButton
appearance="none"
icon
size="small"
>
<AddCircleIcon />
</KButton>
</div>
</SandboxSectionComponent>
<SandboxTitleComponent
is-subtitle
title="Custom button"
/>
<SandboxSectionComponent>
<div class="horizontal-spacing">
<KButton
appearance="none"
class="custom-button"
@click="test"
>
Custom
</KButton>
<KButton
appearance="none"
class="custom-button"
disabled
@click="test"
>
Custom
</KButton>
</div>
</SandboxSectionComponent>
</div>
Expand All @@ -507,4 +599,23 @@ const test = () => {
gap: $kui-space-50;
}
}
/* Low-specificity styles should be able to override */
.custom-button {
background-color: #42b883;
border-radius: 8px;
color: #fff;
font-size: 16px;
font-weight: 600;
padding: 8px 16px;
&:hover:not(:disabled) {
background-color: #33a06f;
transition-duration: .2s;
}
&:disabled {
opacity: 0.3;
}
}
</style>
Loading

0 comments on commit 30fb03a

Please sign in to comment.