Skip to content

Commit

Permalink
feat: CProgress: add size prop
Browse files Browse the repository at this point in the history
- deprecated height prop - display warning message when it is used,
- correct shared props,
- update test and typings
- cleanup
  • Loading branch information
woothu committed Jun 19, 2020
1 parent ede894f commit a056973
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/components/index.d.ts
Expand Up @@ -446,8 +446,7 @@ export declare class CPagination extends Vue {
responsive?: boolean
}

export declare class CProgress extends Vue {
height?: string
export declare class CProgressBar extends Vue {
color?: string
striped?: boolean
animated?: boolean
Expand All @@ -458,7 +457,11 @@ export declare class CProgress extends Vue {
value?: number
}

export declare class CProgressBar extends CProgress {}
export declare class CProgress extends CProgressBar {
height?: string
size?: string
}


type ContentFlat = [NodeFlat]
declare interface NodeFlat {
Expand Down
22 changes: 20 additions & 2 deletions src/components/progress/CProgress.vue
@@ -1,5 +1,8 @@
<template>
<div class="progress" :style="{ height }">
<div
:class="['progress', size && `progress-${size}`]"
:style="{ height }"
>
<slot>
<CProgressBar :value="value"/>
</slot>
Expand All @@ -8,12 +11,27 @@

<script>
import CProgressBar from './CProgressBar'
import props from './progress-props'
import shared from './shared-props'
const props = {
...shared,
height: String,
size: {
type: String,
validator: val => ['', 'xs', 'sm'].includes(val)
},
}
export default {
name:'CProgress',
components: { CProgressBar },
props,
mounted () {
/* istanbul ignore next */
if (this.height && process && process.env && process.env.NODE_ENV === 'development') {
console.error("CProgress component: 'height' prop is deprecated and will be removed in the next version. Use 'size' prop instead or pass custom height in 'style' attribute.")
}
},
provide () {
const progress = {}
Object.defineProperty(progress, 'props', {
Expand Down
14 changes: 6 additions & 8 deletions src/components/progress/CProgressBar.vue
Expand Up @@ -12,28 +12,26 @@
</template>

<script>
import props from './progress-props'
import props from './shared-props'
export default {
name: 'CProgressBar',
props,
inject: {
progress: {
default: undefined
default: { props: {} }
}
},
computed: {
directlyDeclaredProps () {
return Object.keys(this.$options.propsData)
},
injectedProps () {
return this.progress && this.progress.props ? this.progress.props : {}
},
props () {
return Object.keys(props).reduce((computedProps, key) => {
const propIsDirectlyDeclared = this.directlyDeclaredProps.includes(key)
const parentPropExists = this.injectedProps[key] !== undefined
const propIsInherited = parentPropExists && !propIsDirectlyDeclared
computedProps[key] = propIsInherited ? this.injectedProps[key] : this[key]
const parentPropExists = this.progress.props[key] !== undefined
const isInherited = parentPropExists && !propIsDirectlyDeclared
computedProps[key] = isInherited ? this.progress.props[key] : this[key]
return computedProps
}, {})
},
Expand Down
@@ -1,6 +1,4 @@
export default {
height: String,
// These props can be inherited via the child CProgressBar(s)
color: String,
striped: Boolean,
animated: Boolean,
Expand Down
4 changes: 3 additions & 1 deletion src/components/progress/tests/CProgress.spec.js
Expand Up @@ -6,7 +6,9 @@ const defaultWrapper = mount(Component)
const customWrapper = mount(Component, {
propsData: {
color: 'black',
value: 20
value: 20,
size: 'sm',
height: '2rem'
},
attrs: {
class: 'test'
Expand Down
Expand Up @@ -20,6 +20,7 @@ exports[`CProgress renders correctly 1`] = `
exports[`CProgress renders correctly 2`] = `
<div
class="test"
style="height: 2rem;"
>
<div
aria-valuemax="100"
Expand Down

0 comments on commit a056973

Please sign in to comment.