@@ -101,6 +102,7 @@ export default function ProgressBar({
)}
isInFlash={isInFlash}
style={style}
+ styleClassNames={styleClassNames}
/>
{label}
diff --git a/src/progress-bar/internal.tsx b/src/progress-bar/internal.tsx
index f8a0c785a8c..a84d3e2aab9 100644
--- a/src/progress-bar/internal.tsx
+++ b/src/progress-bar/internal.tsx
@@ -26,9 +26,24 @@ interface ProgressProps {
ariaLabelledby?: string;
ariaDescribedby?: string;
style?: ProgressBarProps.Style;
+ styleClassNames?: StyleClassNames;
}
-export const Progress = ({ value, isInFlash, ariaLabel, ariaLabelledby, ariaDescribedby, style }: ProgressProps) => {
+// Style API v2
+export interface StyleClassNames {
+ root?: string;
+ percentage?: string;
+}
+
+export const Progress = ({
+ value,
+ isInFlash,
+ ariaLabel,
+ ariaLabelledby,
+ ariaDescribedby,
+ style,
+ styleClassNames,
+}: ProgressProps) => {
const roundedValue = Math.round(value);
const progressValue = clamp(roundedValue, 0, MAX_VALUE);
@@ -56,14 +71,12 @@ export const Progress = ({ value, isInFlash, ariaLabel, ariaLabelledby, ariaDesc
}}
/>
-
{`${progressValue}%`}
-
+
);
diff --git a/src/progress-bar/styles.scss b/src/progress-bar/styles.scss
index 49bd3e65c11..e0320c5c8aa 100644
--- a/src/progress-bar/styles.scss
+++ b/src/progress-bar/styles.scss
@@ -6,20 +6,47 @@
@use '../internal/styles/tokens' as awsui;
@use '../internal/styles' as styles;
@use '../internal/generated/custom-css-properties/index.scss' as custom-props;
+@use '../internal/styles/style-api' as style-api;
@use './motion';
-$progress-height: var(#{custom-props.$progressBarHeight}, 0.4 * styles.$base-size);
-$progress-border-radius: var(#{custom-props.$progressBarBorderRadius}, 10px);
-$progress-background-color: var(
- #{custom-props.$progressBarBackgroundColor},
- awsui.$color-background-progress-bar-default
+$progress-bar-tokens: style-api.resolve((track-color, value-color, bar-block-size, bar-border-radius), carrier);
+@include style-api.register($progress-bar-tokens);
+@include style-api.docs('root', $progress-bar-tokens);
+@include style-api.docs('percentage', $properties: (color, font-family, font-size, font-weight));
+
+$progress-height: style-api.value(
+ $progress-bar-tokens,
+ bar-block-size,
+ var(#{custom-props.$progressBarHeight}, 0.4 * styles.$base-size)
+);
+$progress-border-radius: style-api.value(
+ $progress-bar-tokens,
+ bar-border-radius,
+ var(#{custom-props.$progressBarBorderRadius}, 10px)
+);
+$progress-background-color: style-api.value(
+ $progress-bar-tokens,
+ track-color,
+ var(#{custom-props.$progressBarBackgroundColor}, awsui.$color-background-progress-bar-default)
+);
+$progress-value-background-color: style-api.value(
+ $progress-bar-tokens,
+ value-color,
+ var(#{custom-props.$progressValueBackgroundColor}, awsui.$color-background-progress-bar-value-default)
);
-$progress-value-background-color: var(
- #{custom-props.$progressValueBackgroundColor},
- awsui.$color-background-progress-bar-value-default
+$progress-flash-background-color: style-api.value(
+ $progress-bar-tokens,
+ track-color,
+ var(#{custom-props.$progressBarBackgroundColor}, awsui.$color-background-progress-bar-flash)
+);
+$progress-flash-value-background-color: style-api.value(
+ $progress-bar-tokens,
+ value-color,
+ var(#{custom-props.$progressValueBackgroundColor}, awsui.$color-background-progress-bar-value-flash)
);
.root {
+ @include style-api.carriers($progress-bar-tokens);
@include styles.styles-reset;
}
@@ -79,7 +106,19 @@ $progress-value-background-color: var(
}
.percentage {
- /* used in test-utils */
+ display: inline-block;
+ font-family: awsui.$font-family-base;
+ -webkit-font-smoothing: auto;
+ -moz-osx-font-smoothing: auto;
+ line-height: awsui.$line-height-body-s;
+ letter-spacing: awsui.$letter-spacing-body-s;
+ color: awsui.$color-text-small;
+ font-size: awsui.$font-size-body-s;
+ font-weight: styles.$font-weight-normal;
+
+ &.percentage-flash {
+ color: currentColor;
+ }
}
@mixin general-progress-background-style {
@@ -131,22 +170,16 @@ $progress-value-background-color: var(
}
&.progress-flash {
- background-color: var(#{custom-props.$progressBarBackgroundColor}, awsui.$color-background-progress-bar-flash);
+ background-color: $progress-flash-background-color;
&::-webkit-progress-bar {
- background-color: var(#{custom-props.$progressBarBackgroundColor}, awsui.$color-background-progress-bar-flash);
+ background-color: $progress-flash-background-color;
}
&::-webkit-progress-value {
- background-color: var(
- #{custom-props.$progressValueBackgroundColor},
- awsui.$color-background-progress-bar-value-flash
- );
+ background-color: $progress-flash-value-background-color;
}
&::-moz-progress-bar {
- background-color: var(
- #{custom-props.$progressValueBackgroundColor},
- awsui.$color-background-progress-bar-value-flash
- );
+ background-color: $progress-flash-value-background-color;
}
}
}
diff --git a/src/slider/__tests__/style-api.test.tsx b/src/slider/__tests__/style-api.test.tsx
new file mode 100644
index 00000000000..765ef577458
--- /dev/null
+++ b/src/slider/__tests__/style-api.test.tsx
@@ -0,0 +1,44 @@
+// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+// SPDX-License-Identifier: Apache-2.0
+import React from 'react';
+import { render } from '@testing-library/react';
+
+import Slider from '../../../lib/components/slider';
+import createWrapper from '../../../lib/components/test-utils/dom';
+
+import styles from '../../../lib/components/slider/styles.css.js';
+
+function renderSlider(element: React.ReactElement) {
+ const { container } = render(element);
+ return { container, wrapper: createWrapper(container).findSlider()! };
+}
+
+const slots = { root: 'a', handle: 'b', track: 'c', range: 'd' };
+
+describe('Slider Style API v2 (implicit styleClassNames)', () => {
+ test('applies styleClassNames to the root and handle slots only', () => {
+ const { container, wrapper } = renderSlider(
+
{}}
+ {...({ styleClassNames: slots } as any)}
+ />
+ );
+
+ expect(wrapper.getElement()).toHaveClass('a');
+ expect(container.querySelector(`.${styles.thumb}`)).toHaveClass('b');
+ expect(container.querySelector('.c')).toBeNull();
+ expect(container.querySelector('.d')).toBeNull();
+ });
+
+ test('does not leak the styleClassNames prop to the DOM', () => {
+ const { container } = renderSlider(
+ {}} {...({ styleClassNames: slots } as any)} />
+ );
+ expect(container.querySelector('[styleClassNames]')).toBeNull();
+ });
+});
diff --git a/src/slider/internal.tsx b/src/slider/internal.tsx
index e1de93e7e92..08fc4e56d8a 100644
--- a/src/slider/internal.tsx
+++ b/src/slider/internal.tsx
@@ -27,7 +27,14 @@ import {
import styles from './styles.css.js';
+// Style API v2
+export interface StyleClassNames {
+ root?: string;
+ handle?: string;
+}
+
interface InternalSliderProps extends SliderProps, InternalBaseComponentProps {
+ styleClassNames?: StyleClassNames;
style?: SliderProps['style'];
}
@@ -47,6 +54,7 @@ export default function InternalSlider({
valueFormatter,
i18nStrings,
style,
+ styleClassNames,
__internalRootRef,
...rest
}: InternalSliderProps) {
@@ -132,7 +140,7 @@ export default function InternalSlider({