Skip to content

Commit

Permalink
feat: add ArcUnits
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamKelley committed May 30, 2024
1 parent 896dc34 commit d8fffbc
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ArcUnitLabel,
ArcScale,
Chart,
ArcUnits,
} from '../../../src';

const Neutral70 = '#EBECF0';
Expand Down Expand Up @@ -42,6 +43,8 @@ const ReportCardEmpowermentMetricDualRadialGauge = (props: {
valueSecondary: number;
radiusSecondary: number;
radiusRatioSecondary: number;
// extra
unitsOffset?: number;
}) => {
const {
valueMin,
Expand All @@ -52,6 +55,7 @@ const ReportCardEmpowermentMetricDualRadialGauge = (props: {
radiusRatioPrimary,
radiusSecondary,
radiusRatioSecondary,
unitsOffset,
} = props;

return (
Expand All @@ -77,15 +81,17 @@ const ReportCardEmpowermentMetricDualRadialGauge = (props: {
>
<ArcSweep style={{ fill: Neutral70 }} />
<ArcCircle at={valuePrimary} style={{ fill: Purple600 }} />
<ArcUnitLabel at={1} style={unitLabelStyle(1, valuePrimary)}>
Too easy
</ArcUnitLabel>
<ArcUnitLabel at={2} style={unitLabelStyle(2, valuePrimary)}>
Just right
</ArcUnitLabel>
<ArcUnitLabel at={3} style={unitLabelStyle(3, valuePrimary)}>
Too hard
</ArcUnitLabel>
<ArcUnits offset={unitsOffset}>
<ArcUnitLabel at={1} style={unitLabelStyle(1, valuePrimary)}>
Too easy
</ArcUnitLabel>
<ArcUnitLabel at={2} style={unitLabelStyle(2, valuePrimary)}>
Just right
</ArcUnitLabel>
<ArcUnitLabel at={3} style={unitLabelStyle(3, valuePrimary)}>
Too hard
</ArcUnitLabel>
</ArcUnits>
</Arc>
<Arc
radius={radiusSecondary}
Expand Down Expand Up @@ -113,6 +119,7 @@ const meta: Meta<typeof ReportCardEmpowermentMetricDualRadialGauge> = {
radiusRatioPrimary: 0.77,
radiusSecondary: 93,
radiusRatioSecondary: 0.87,
unitsOffset: 8,
},
argTypes: {
valuePrimary: {
Expand All @@ -131,6 +138,14 @@ const meta: Meta<typeof ReportCardEmpowermentMetricDualRadialGauge> = {
step: 1,
},
},
unitsOffset: {
control: {
type: 'range',
min: 0,
max: 16,
step: 1,
},
},
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/ArcUnitLabel/ArcUnitLabelProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ArcUnitLabelProps
*/
at: number;
/**
* The offset of the unit label from the arc's (primary/outer) radius
* The offset of the unit label from the arc's (primary/outer) radius.
*/
offset?: number;
/**
Expand Down
17 changes: 17 additions & 0 deletions packages/components/src/ArcUnits/ArcUnits.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { ArcUnitsProps } from './ArcUnitsProps';

export const ArcUnits = (props: ArcUnitsProps) => {
const { children, offset, ...other } = props;

return React.Children.map(children, (child) => {
if (React.isValidElement<Omit<ArcUnitsProps, 'children'>>(child)) {
return React.cloneElement(child, {
offset: child.props.offset ?? offset,
...other,
});
}

return child;
});
};
6 changes: 6 additions & 0 deletions packages/components/src/ArcUnits/ArcUnitsProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import { ArcUnitsParams } from '../utils';

export interface ArcUnitsProps extends ArcUnitsParams {
children: React.ReactNode;
}
2 changes: 2 additions & 0 deletions packages/components/src/ArcUnits/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ArcUnits';
export * from './ArcUnitsProps';
1 change: 1 addition & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './ArcCircle';
export * from './ArcSegments';
export * from './ArcSegmentsSweep';
export * from './ArcSweep';
export * from './ArcUnits';
export * from './ArcUnitLabel';
export * from './ArcScale';
export * from './Bar';
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/utils/arc-units.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type ArcUnitsParams = {
/**
* The offset of the unit label from the arc's (primary/outer) radius.
*/
offset?: number;
};
1 change: 1 addition & 0 deletions packages/components/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './arc';
export * from './arc-circle';
export * from './arc-scale';
export * from './arc-segments';
export * from './arc-units';
export * from './bar';
export * from './bar-fill';
export * from './bar-scale';
Expand Down

0 comments on commit d8fffbc

Please sign in to comment.