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

chore(meter, slider): fix spacing of min and max labels #3488

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .changeset/famous-paws-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@twilio-paste/slider': patch
'@twilio-paste/core': patch
---

[Slider] Add spacing between min and max range labels, wrap overflow content onto second line, and right-align max range label.
6 changes: 6 additions & 0 deletions .changeset/forty-carrots-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@twilio-paste/meter': patch
'@twilio-paste/core': patch
---

[Meter] Add spacing between the min and max labels for readability, right-align the max label, and make overflow min/max labels wrap to second line.
10 changes: 9 additions & 1 deletion packages/paste-core/components/meter/src/Meter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ const Meter = React.forwardRef<HTMLMeterElement, MeterProps>(
display="flex"
flexDirection="row"
justifyContent="space-between"
columnGap="space20"
marginTop="space20"
aria-hidden="true"
overflowWrap="anywhere"
element={`${element}_MIN_MAX_WRAPPER`}
>
{minLabel ? (
Expand All @@ -84,7 +86,13 @@ const Meter = React.forwardRef<HTMLMeterElement, MeterProps>(
<span />
)}
{maxLabel ? (
<Text as="span" color="colorTextWeak" fontWeight="fontWeightNormal" element={`${element}_MAX`}>
<Text
as="span"
color="colorTextWeak"
fontWeight="fontWeightNormal"
textAlign="end"
element={`${element}_MAX`}
>
{maxLabel}
</Text>
) : (
Expand Down
10 changes: 9 additions & 1 deletion packages/paste-core/components/meter/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ export const Wrapped = (): React.ReactElement => {
<MeterLabel htmlFor={meterId} valueLabel="54,730 is the current value of this Meter">
Storage space used on this account that belongs to you
</MeterLabel>
<Meter id={meterId} value={54730} minValue={0} maxValue={600000} aria-describedby={helpTextId} />
<Meter
id={meterId}
value={54730}
minValue={0}
maxValue={600000}
aria-describedby={helpTextId}
minLabel="000000000000GB"
maxLabel="100000000000GB"
/>
<HelpText id={helpTextId}>Helpful text</HelpText>
</Box>
);
Expand Down
4 changes: 3 additions & 1 deletion packages/paste-core/components/slider/src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,18 @@ export const Slider = React.forwardRef<HTMLDivElement, SliderProps>((props, ref)
element={`${element}_RANGE_LABELS`}
display="flex"
justifyContent="space-between"
columnGap="space20"
fontSize="fontSize30"
lineHeight="lineHeight30"
fontWeight="fontWeightNormal"
color="colorTextWeak"
overflowWrap="anywhere"
>
<Box element={`${element}_RANGE_LABELS_MIN`}>
<ScreenReaderOnly>{i18nMinRangeLabel}</ScreenReaderOnly>
{remappedProps.numberFormatter.format(minValue)}
</Box>
<Box element={`${element}_RANGE_LABELS_MAX`}>
<Box element={`${element}_RANGE_LABELS_MAX`} textAlign="end">
<ScreenReaderOnly>{i18nMaxRangeLabel}</ScreenReaderOnly>
{remappedProps.numberFormatter.format(maxValue)}
</Box>
Expand Down
28 changes: 28 additions & 0 deletions packages/paste-core/components/slider/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,34 @@ export const HiddenRangeLabels = (): React.ReactNode => {
);
};

export const Wrapped = (): React.ReactNode => {
const [value, setValue] = React.useState<number>(0.75);
const sliderId = useUID();
const helpTextId = useUID();

return (
<Form maxWidth="size20">
<FormControl>
<Label htmlFor={sliderId}>Volume</Label>
<Slider
id={sliderId}
aria-describedby={helpTextId}
value={value}
minValue={10000000}
maxValue={100000000000}
step={0.01}
onChange={(newValue) => setValue(newValue)}
numberFormatter={PercentFormatter}
/>
<HelpText id={helpTextId}>
I saw an ad yesterday that said “Radio for sale $1, volume is stuck on full blast”. I said to myself “well, I
can’t turn that down.”
</HelpText>
</FormControl>
</Form>
);
};

export const CustomizedSlider = (): React.ReactNode => {
const activeTheme = useTheme();
const [value, setValue] = React.useState<number>(32);
Expand Down
Loading