From 8bc5dc0719c3d827808e8ca4bcaabbdd18ca870f Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 14 Dec 2023 11:15:43 -0500 Subject: [PATCH 1/2] feat: Update Switch component styling (#982) Adds new 'labelStyle: "centered"'. This will stack the label on top of the switch and center both elements in the column. Updates how tooltips are rendered for Switches. Now includes an icon to denote there is a tooltip, rather than requiring the user to discover it by hovering over it. Adds this tooltip functionality to the Label component, though it is only currently used by Switch. At some point it would be good to move all Tooltips to this sort of UX. --- src/components/Label.tsx | 35 ++++++++--- src/inputs/Switch.stories.tsx | 8 +++ src/inputs/Switch.tsx | 115 ++++++++++++++++------------------ 3 files changed, 90 insertions(+), 68 deletions(-) diff --git a/src/components/Label.tsx b/src/components/Label.tsx index 84e817edc..1f96b1ea2 100644 --- a/src/components/Label.tsx +++ b/src/components/Label.tsx @@ -1,8 +1,11 @@ -import React, { LabelHTMLAttributes } from "react"; +import React, { LabelHTMLAttributes, ReactNode } from "react"; import { VisuallyHidden } from "react-aria"; -import { Css } from "src/Css"; +import { Css, Font, Only, Palette, Xss } from "src/Css"; +import { Icon } from "src"; -interface LabelProps { +type LabelXss = Font | "color"; + +interface LabelProps { // We don't usually have `fooProps`-style props, but this is for/from react-aria labelProps?: LabelHTMLAttributes; label: string; @@ -11,22 +14,38 @@ interface LabelProps { hidden?: boolean; contrast?: boolean; multiline?: boolean; + tooltip?: ReactNode; + // Removes margin bottom if true - This is different from InlineLabel. InlineLabel expects to be rendered visually within the field element. Rather just on the same line. + inline?: boolean; + xss?: X; } /** An internal helper component for rendering form labels. */ -export const Label = React.memo((props: LabelProps) => { - const { labelProps, label, hidden, suffix, contrast = false, ...others } = props; +function LabelComponent, X>>(props: LabelProps) { + const { labelProps, label, hidden, suffix, contrast = false, tooltip, inline, xss, ...others } = props; const labelEl = ( -