Skip to content

Commit

Permalink
break up progress bar types using discriminating unions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Kessaris committed Jul 26, 2023
1 parent 1a2a68f commit 46619ea
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions src/progress-bar/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,12 @@
import { BaseComponentProps } from '../internal/base-component';
import { NonCancelableEventHandler } from '../internal/events';

export interface ProgressBarProps extends BaseComponentProps {
interface BaseProgressBarProps extends BaseComponentProps {
/**
* Indicates the current progress as a percentage. The value must be between 0 and 100. Decimals are rounded.
*/
value?: number;

/**
* Specifies the progress type.
*
* @defaultValue 'percentage'
*/
type?: ProgressBarProps.ContentType;

/**
* Specifies the maximum value of the progress when type ratio is selected.
*
* @defaultValue 100
*/
maxValue?: number;

/**
* Control localization of the progress bar value.
*
* @defaultValue If type === `percentage`, `${value}%`
* @defaultValue If type === `ratio`, `${value} of ${maxValue}`
*/
ariaValueText?: string;

/**
* Specifies the status of the progress bar. You can set it to one of the following:
*
Expand Down Expand Up @@ -91,6 +69,41 @@ export interface ProgressBarProps extends BaseComponentProps {
onResultButtonClick?: NonCancelableEventHandler;
}

interface PercentageProgressBarProps extends BaseProgressBarProps {
/**
* Specifies the progress type.
*
* @defaultValue 'percentage'
*/
type?: 'percentage';
}

interface RatioProgressBarProps extends BaseProgressBarProps {
/**
* Specifies the progress type.
*
* @defaultValue 'percentage'
*/
type: 'ratio';

/**
* Specifies the maximum value of the progress when type ratio is selected.
*
* @defaultValue 100
*/
maxValue?: number;

/**
* Control localization of the progress bar value.
*
* @defaultValue If type === `percentage`, `${value}%`
* @defaultValue If type === `ratio`, `${value} of ${maxValue}`
*/
ariaValueText?: string;
}

export type ProgressBarProps = PercentageProgressBarProps | RatioProgressBarProps;

export namespace ProgressBarProps {
export type Status = 'in-progress' | 'success' | 'error';
export type Variant = 'standalone' | 'flash' | 'key-value';
Expand Down

0 comments on commit 46619ea

Please sign in to comment.