Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #525 from owncloud/feature/a11y-documentation/star
Browse files Browse the repository at this point in the history
Refactor and document OcStar(Toggle)
  • Loading branch information
Lukas Hirt authored Nov 4, 2019
2 parents 5cf4b0b + 01472f2 commit d7d89a1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/elements/OCStar.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<template>
<div class="oc-star">
<oc-icon v-show="shining" class="oc-star-shining" name="star" />
<oc-icon v-show="!shining" class="oc-star-dimm" name="star_border" />
</div>
<oc-icon :class="shining ? 'oc-star-shining' : 'oc-star-dimm'" name="star" />
</template>
<script>
/**
Expand Down
2 changes: 1 addition & 1 deletion src/elements/OcButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default {
type: String,
default: "default",
validator: value => {
return value.match(/(default|primary|secondary|danger)/)
return value.match(/(default|primary|secondary|danger|raw)/)
},
},
/**
Expand Down
65 changes: 65 additions & 0 deletions src/elements/OcStarToggle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<template>
<oc-button
variation="raw"
role="switch"
:aria-checked="checked.toString()"
:aria-label="label"
@click="$_ocStarToggle_togglePressed"
>
<oc-star :shining="checked" />
</oc-button>
</template>

<script>
import OcButton from "./OcButton"
/**
*
* ## Accessibility
*
* ### Communicating the buttons toggle role to screen readers
* With `role="switch"` screen readers are informed that the button is a toggle, which will have two states: on and off. Toggle buttons like this should be used instead of checkboxes (which make only really sense in form contexts – [reasoning and more background](https://inclusive-components.design/toggle-button/#thisdoesntquitefeelright)).
*
* ### Communicating the toggle's state to screen readers
*
* Buttons with `switch` role can convey their state with the `aria-checked` attribute. When using this component, authors can set the initial state of OcStarToggle with the `checked` prop.
*
* */
export default {
name: "oc-star-toggle",
components: { OcButton },
status: "review",
release: "1.0.0",
methods: {
$_ocStarToggle_togglePressed: function() {
this.checked = !this.checked
},
},
props: {
/**
* Initial state of toggle button
**/
checked: {
type: Boolean,
required: false,
default: false,
},
/**
* Accessible name of toggle button
**/
label: {
type: String,
required: true,
},
},
}
</script>
<docs>
```jsx
<h3>OcStarToggle initially not checked</h3>
<oc-star-toggle label="Favorite this item"></oc-star-toggle>
<h3>OcStarToggle initially checked</h3>
<oc-star-toggle checked="true" label="Favorite this item"></oc-star-toggle>
```
</docs>
8 changes: 8 additions & 0 deletions src/styles/theme/helper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
cursor: pointer;
}

.oc-button-reset {
@extend .uk-padding-remove;
-webkit-appearance: none;
background: transparent;
font: inherit;
border: none;
}

.oc-align-self-center {
align-self: center;
}
Expand Down
4 changes: 4 additions & 0 deletions src/styles/theme/oc-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@
}
}
}

.oc-button.uk-button-raw {
@extend .oc-button-reset;
}

0 comments on commit d7d89a1

Please sign in to comment.