From 5f1d20319a5618c7ce884fde3e8c4c9a68c21e39 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:47:03 +0100 Subject: [PATCH] Segment Control (#5170) * Segment * Fix type errors * Fix HUG --- apps/web/pages/sandbox/form.tsx | 12 +++++++++++ packages/ui/v2/core/Segment.tsx | 36 +++++++++++++++++++++++++++++++++ packages/ui/v2/core/index.ts | 2 ++ 3 files changed, 50 insertions(+) create mode 100644 packages/ui/v2/core/Segment.tsx diff --git a/apps/web/pages/sandbox/form.tsx b/apps/web/pages/sandbox/form.tsx index 5b4fc55e32..a6d3342aec 100644 --- a/apps/web/pages/sandbox/form.tsx +++ b/apps/web/pages/sandbox/form.tsx @@ -1,6 +1,7 @@ import React from "react"; import { Label, Input, TextField } from "@calcom/ui/form/fields"; +import { Segment, SegmentOption } from "@calcom/ui/v2/core"; import { sandboxPage } from "."; @@ -14,6 +15,17 @@ const page = sandboxPage(() => (
+ {/* Adding to sandbox cause storybook doesnt like radix tailwind :S */} +
+ + One + Two + Three + + Four + + +
)); diff --git a/packages/ui/v2/core/Segment.tsx b/packages/ui/v2/core/Segment.tsx new file mode 100644 index 0000000000..90ddbfad4f --- /dev/null +++ b/packages/ui/v2/core/Segment.tsx @@ -0,0 +1,36 @@ +import * as RadioGroup from "@radix-ui/react-radio-group"; +import React from "react"; + +import { Label } from "./form"; + +type SegmentProps = { + label: string; + children: React.ReactNode; +} & RadioGroup.RadioGroupProps; + +export function Segment({ label, children, ...rest }: SegmentProps) { + return ( +
+
+ {label && } + + {children} + +
+
+ ); +} + +type SegmentOptionProps = { value: string; children: React.ReactNode } & RadioGroup.RadioGroupItemProps; +export function SegmentOption({ value, children, ...rest }: SegmentOptionProps) { + return ( + + {children} + + ); +} diff --git a/packages/ui/v2/core/index.ts b/packages/ui/v2/core/index.ts index e7a22dbd93..0d0f8de7dd 100644 --- a/packages/ui/v2/core/index.ts +++ b/packages/ui/v2/core/index.ts @@ -31,4 +31,6 @@ export { default as HorizontalTabs, HorizontalTabItem } from "./navigation/tabs/ export type { VerticalTabItemProps } from "./navigation/tabs/VerticalTabItem"; export type { HorizontalTabItemProps } from "./navigation/tabs/HorizontalTabItem"; export * from "./Portal"; +export * from "./Segment"; export { default as SettingsToggle } from "./SettingsToggle"; +