diff --git a/packages/dnb-design-system-portal/src/pages/uilib/components/progress/Examples.js b/packages/dnb-design-system-portal/src/pages/uilib/components/progress/Examples.js index 7037f4fe519..f84089ad527 100644 --- a/packages/dnb-design-system-portal/src/pages/uilib/components/progress/Examples.js +++ b/packages/dnb-design-system-portal/src/pages/uilib/components/progress/Examples.js @@ -10,11 +10,19 @@ class Example extends PureComponent { render() { return ( - + + {/* @jsx */ ` + + `} + + {/* @jsx */ ` `} diff --git a/packages/dnb-design-system-portal/src/pages/uilib/components/progress/progress-properties.md b/packages/dnb-design-system-portal/src/pages/uilib/components/progress/progress-properties.md index 557510439fe..729fe7080ee 100644 --- a/packages/dnb-design-system-portal/src/pages/uilib/components/progress/progress-properties.md +++ b/packages/dnb-design-system-portal/src/pages/uilib/components/progress/progress-properties.md @@ -7,6 +7,7 @@ draft: true | Properties | Description | | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | `label` | _(optional)_ if a text label is needed. Defaults to `null`. | +| `progress` | _(optional)_ to visualize a static **percentage** (0-100) as a progress state. Defaults to `null`. | | `visible` | _(optional)_ defines the visibility of the progress. Toggeling the `visible` property to false will force a fade-out animation. Defaults to `true`. | | `type` | _(optional)_ defines the **type** of progress, like `circular`. Defaults to `circular`. | | `no_animation` | _(optional)_ disables the fade-in and fade-out animation. Defaults to false. | diff --git a/packages/dnb-ui-lib/src/components/progress/Progress.js b/packages/dnb-ui-lib/src/components/progress/Progress.js index f13cd1f1d4c..277c8c10930 100644 --- a/packages/dnb-ui-lib/src/components/progress/Progress.js +++ b/packages/dnb-ui-lib/src/components/progress/Progress.js @@ -5,8 +5,7 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' -// import classnames from 'classnames' -// import keycode from 'keycode' +import classnames from 'classnames' import { registerElement // validateDOMAttributes, @@ -14,40 +13,39 @@ import { } from '../../shared/component-helper' import ProgressCircular from './ProgressCircular' -const renderProps = { - render: null -} +const renderProps = {} export const propTypes = { - label: PropTypes.string, + // label: PropTypes.string, visible: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), - type: PropTypes.oneOf(['circular']), - no_animation: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), - min_time: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - variant: PropTypes.oneOf(['primary', 'secondary']), - size: PropTypes.oneOf(['large', 'medium']), + // type: PropTypes.oneOf(['circular']), + // no_animation: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), + // min_time: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + // variant: PropTypes.oneOf(['primary', 'secondary']), + size: PropTypes.oneOf(['small', 'medium', 'large', 'huge']), + progress: PropTypes.number // id: PropTypes.string, // class: PropTypes.string, /** React props */ - className: PropTypes.string, - children: PropTypes.oneOfType([ - PropTypes.object, - PropTypes.node, - PropTypes.func - ]), + // className: PropTypes.string, + // children: PropTypes.oneOfType([ + // PropTypes.object, + // PropTypes.node, + // PropTypes.func + // ]), // Web Component props - render: PropTypes.func } export const defaultProps = { - label: null, + // label: null, visible: true, - type: 'circular', - no_animation: false, - min_time: null, - variant: 'primary', + // type: 'circular', + // no_animation: false, + // min_time: null, + // variant: 'primary', size: 'medium', + progress: null, // id: null, // class: null, @@ -70,8 +68,11 @@ export default class Progress extends PureComponent { static getDerivedStateFromProps(props, state) { if (state._listenForPropChanges) { - if (props.visible && state._visible !== props.visible) { - state.visible = state._visible = props.visible + if (props.visible) { + state.visible = Boolean(props.visible) + } + if (parseFloat(props.progress) > -1) { + state.visible = props.progress } } state._listenForPropChanges = true @@ -88,23 +89,28 @@ export default class Progress extends PureComponent { this.state = { _listenForPropChanges: true, visible, - _visible: visible + progress: props.progress } - - // this._tablistRef = React.createRef() } render() { const { + size, + progress: _progress, //eslint-disable-line visible: _visible //eslint-disable-line - // ...props + // ...attributes } = this.props - // const { visible } = this.state + const { progress, visible } = this.state return ( -
- +
+
) } diff --git a/packages/dnb-ui-lib/src/components/progress/ProgressCircular.js b/packages/dnb-ui-lib/src/components/progress/ProgressCircular.js index 9889994add9..6711e62f042 100644 --- a/packages/dnb-ui-lib/src/components/progress/ProgressCircular.js +++ b/packages/dnb-ui-lib/src/components/progress/ProgressCircular.js @@ -5,24 +5,67 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' +import classnames from 'classnames' + +export const propTypes = { + size: PropTypes.string, + progress: PropTypes.number, + maxOffset: PropTypes.number +} +export const defaultProps = { + size: null, + progress: null, + maxOffset: 88 +} export default class ProgressCircular extends PureComponent { + static propTypes = propTypes + static defaultProps = defaultProps render() { + const { size, maxOffset, progress } = this.props + const strokeDashoffset = -((maxOffset / 100) * progress) + const hasProgress = parseFloat(progress) > -1 return ( -
- - - +
+ + +
) } } -const Circle = ({ className }) => ( +const Circle = ({ className, ...rest }) => ( ( - + + + + )