Skip to content

Commit

Permalink
feat(component): add darkMode
Browse files Browse the repository at this point in the history
adds toggle between normal and dark themes instead of explicitly naming the classes
  • Loading branch information
web-mech committed Jan 28, 2020
1 parent c4cde96 commit 62226c2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
38 changes: 36 additions & 2 deletions src/PercentageCircle.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<template>
<div
@click="(e) => $emit('click', e)"
@click="onClick"
class="c100"
:class="[`p${innerPercent}`, !complete ? activeColor : completeColor, size]">
:class="[
`p${innerPercent}`,
!complete ? activeColor : completeColor, size,
darkMode ? 'dark' : '']">
<span>{{innerPercent}}%</span>
<div class="slice">
<div class="bar"></div>
Expand All @@ -14,29 +17,51 @@
<script>
export default {
props: {
/**
* Percentage of progress (0-100)
*/
percent: {
type: Number,
default: 0
},
/**
* Size of percentage circle [small, large, huge]
*/
size: {
type: String,
default: 'small'
},
/**
* Color when active.
*/
activeColor: {
type: String,
default: 'blue'
},
/**
* Color when complete.
*/
completeColor: {
type: String,
default: ''
},
/**
* Animate percentage changes.
*/
animate: {
type: Boolean,
default: false
},
/**
* Only applicable when animated is set to true. Speed in which animation changes happen
*/
refreshRate: {
type: Number,
default: 5
},
darkMode: {
type: Boolean,
default: false
}
},
computed: {
Expand Down Expand Up @@ -90,6 +115,15 @@
this.stepTo()
}, this.refreshRate)
}
},
onClick(event) {
/**
* Click event.
*
* @event success
* @property {object} click event object
*/
this.$emit('click', event)
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions stories/1-ProgressCircle.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { action } from '@storybook/addon-actions';
import { linkTo } from '@storybook/addon-links';
import { withKnobs, number, select } from '@storybook/addon-knobs'
import { withKnobs, number, select, boolean } from '@storybook/addon-knobs'

import PercentageCircle from '../src/PercentageCircle';

Expand Down Expand Up @@ -33,11 +33,8 @@ const sizeOptions = {

const colorOptions = {
Blue: '',
DarkMode: 'dark',
Green: 'green',
GreenDarkmode: 'green dark',
Orange: 'orange',
OrangeDark: 'orange dark',
}

export const KitchenSink = () => ({
Expand All @@ -54,9 +51,12 @@ export const KitchenSink = () => ({
},
completeColor: {
default: select('Complete Color', colorOptions, '')
},
darkMode: {
default: boolean('Dark Mode', false)
}
},
template: '<PercentageCircle @click="recountUp" :percent="percent" :size="size" :active-color="activeColor" :complete-color="completeColor"></PercentageCircle>',
template: '<PercentageCircle @click="recountUp" :percent="percent" :size="size" :active-color="activeColor" :complete-color="completeColor" :dark-mode="darkMode"></PercentageCircle>',
});


Expand All @@ -77,6 +77,9 @@ export const Animated = () => ({
},
completeColor: {
default: select('Complete Color', colorOptions, '')
},
darkMode: {
default: boolean('Dark Mode', false)
}
},
template: `
Expand All @@ -87,6 +90,7 @@ export const Animated = () => ({
:size="size"
:active-color="activeColor"
:refresh-rate="refreshRate"
:dark-mode="darkMode"
:complete-color="completeColor">
</PercentageCircle>`,
data() {
Expand Down

0 comments on commit 62226c2

Please sign in to comment.