Skip to content

Commit

Permalink
Segment Control (calcom#5170)
Browse files Browse the repository at this point in the history
* Segment

* Fix type errors

* Fix HUG
  • Loading branch information
sean-brydon authored and haffla committed Nov 22, 2022
1 parent d123ea5 commit 2d390df
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 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 ".";

Expand All @@ -14,6 +15,17 @@ const page = sandboxPage(() => (
</div>
<div>
<TextField name="test-02" label="TextField" placeholder="it has an input baked in" />
{/* Adding to sandbox cause storybook doesnt like radix tailwind :S */}
<div className="pt-4">
<Segment label="Test" value="Test">
<SegmentOption value="Test">One</SegmentOption>
<SegmentOption value="2">Two</SegmentOption>
<SegmentOption value="3">Three</SegmentOption>
<SegmentOption value="4" disabled>
Four
</SegmentOption>
</Segment>
</div>
</div>
</div>
));
Expand Down
36 changes: 36 additions & 0 deletions 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 (
<div>
<div className="inline-flex flex-col">
{label && <Label>{label}</Label>}
<RadioGroup.Root
className="flex space-x-1 rounded-md border-gray-200 bg-white p-[2px] text-sm font-medium leading-5 "
{...rest}>
{children}
</RadioGroup.Root>
</div>
</div>
);
}

type SegmentOptionProps = { value: string; children: React.ReactNode } & RadioGroup.RadioGroupItemProps;
export function SegmentOption({ value, children, ...rest }: SegmentOptionProps) {
return (
<RadioGroup.Item
value={value}
className="radix-disabled:opacity-40 radix-state-checked:bg-gray-200 radix-state-checked:hover:bg-gray-200 rounded-[4px] py-[6px] px-3 hover:bg-gray-100"
{...rest}>
{children}
</RadioGroup.Item>
);
}
2 changes: 2 additions & 0 deletions packages/ui/v2/core/index.ts
Expand Up @@ -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";

0 comments on commit 2d390df

Please sign in to comment.