Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ProgressBar): add to @carbon/styles #9148

Merged
merged 8 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright IBM Corp. 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React, { useState, useEffect } from 'react';

import { unstable_ProgressBar as ProgressBar } from 'carbon-components-react';

export default {
title: 'Experimental/unstable_ProgressBar',

parameters: {
component: ProgressBar,
},
};

export const _ProgressBar = () => (
<ProgressBar
label="Progress bar label"
helperText="Optional helper text"
value={75}
/>
);

export const Indeterminate = () => (
<ProgressBar label="Progress bar label" helperText="Optional helper text" />
);

export const Example = () => {
const size = 728;
const [progress, setProgress] = useState(0);

useEffect(() => {
setTimeout(() => {
const interval = setInterval(() => {
setProgress((currentProgress) => {
const advancement = Math.random() * 8;
if (currentProgress + advancement < size) {
return currentProgress + advancement;
} else {
clearInterval(interval);
return size;
}
});
}, 50);
}, 3000);
}, []);

const running = progress > 0;

let helperText = running
? `${progress.toFixed(1)}MB of ${size}MB`
: 'Fetching assets...';
if (progress >= size) {
helperText = 'Done';
}

return (
<ProgressBar
value={running ? progress : null}
max={size}
label="Export data"
helperText={helperText}
/>
);
};
8 changes: 8 additions & 0 deletions packages/carbon-react/src/components/ProgressBar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

export { ProgressBar } from 'carbon-components-react';
26 changes: 26 additions & 0 deletions packages/styles/scss/components/__tests__/progress-bar-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright IBM Corp. 2018, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment node
*/

'use strict';

const { SassRenderer } = require('@carbon/test-utils/scss');

const { render } = SassRenderer.create(__dirname);

describe('scss/components/progress-bar', () => {
test('Public API', async () => {
const { unwrap } = await render(`
@use 'sass:meta';
@use '../progress-bar';

$_: get('mixin', meta.mixin-exists('progress-bar', 'progress-bar'));
`);
expect(unwrap('mixin')).toBe(true);
});
});
1 change: 1 addition & 0 deletions packages/styles/scss/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
@use 'pagination';
@use 'pagination-nav';
@use 'select';
@use 'progress-bar';
@use 'progress-indicator';
@use 'tabs';
11 changes: 11 additions & 0 deletions packages/styles/scss/components/progress-bar/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Copyright IBM Corp. 2018, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@forward 'progress-bar';
@use 'progress-bar';

@include progress-bar.progress-bar;
82 changes: 82 additions & 0 deletions packages/styles/scss/components/progress-bar/_progress-bar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Copyright IBM Corp. 2021
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use '../../config' as *;
@use '../../motion' as *;
@use '../../spacing' as *;
@use '../../theme' as *;
@use '../../type' as *;
@use '../../utilities/convert' as *;

/// Progress Bar styles
/// @access public
/// @group progress-bar
@mixin progress-bar {
.#{$prefix}--progress-bar__label {
@include type-style('body-short-01');

display: block;
margin-bottom: $spacing-03;
color: $text-primary;
}

.#{$prefix}--progress-bar__track {
position: relative;
width: 100%;
height: rem(8px);
background-color: $layer;
}

.#{$prefix}--progress-bar__bar {
display: block;
width: 100%;
height: 100%;
background-color: $interactive;
transform: scaleX(0);
transform-origin: 0 50%;
transition: transform $duration-fast-02 motion(standard, productive);
}

.#{$prefix}--progress-bar--indeterminate
.#{$prefix}--progress-bar__track::after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
animation-duration: 1400ms;
animation-iteration-count: infinite;
animation-name: progress-bar-indeterminate;
animation-timing-function: linear;
background-image: linear-gradient(
90deg,
$interactive 12.5%,
transparent 12.5%
);
background-position-x: 0%;
background-size: 200% 100%;
content: '';
}

.#{$prefix}--progress-bar__helper-text {
@include type-style('helper-text-01');

margin-top: $spacing-02;
color: $text-secondary;
}

@keyframes progress-bar-indeterminate {
0% {
background-position-x: 25%;
}

80%,
100% {
background-position-x: -105%;
}
}
}