Skip to content

Commit

Permalink
feat: add Flex and Text components (#176)
Browse files Browse the repository at this point in the history
* feat: add text component

* feat: add flex component

* feat: export text and flex component

* chore: deprecate old flex and text component

* doc: update text component docs

* docs: add docs for flex component
  • Loading branch information
rsbh authored Nov 19, 2024
1 parent 4d4b8b5 commit 926a89c
Show file tree
Hide file tree
Showing 12 changed files with 510 additions and 23 deletions.
56 changes: 56 additions & 0 deletions apps/www/content/primitives/components/flex.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: Flex
description:
---

## Preview

<Preview>
<Flex gap="large">
<Flex gap="small" direction="column">
<Button variant="primary">Primary button</Button>
<Button variant="primary">Primary button</Button>
<Button variant="primary">Primary button</Button>
</Flex>
<Flex gap="small" direction="column">
<Button variant="primary">Primary button</Button>
<Button variant="primary">Primary button</Button>
<Button variant="primary">Primary button</Button>
</Flex>
</Flex>
</Preview>

## Installation

Install the component from your command line.

<LiveProvider>
<LiveEditor code={`npm install @raystack/apsara`} border />
</LiveProvider>

## Props

The `Flex` component accepts the following props:

- `gap`: sets the gutter space between row and columns
- `wrap`: sets whether flex items are forced onto one line or can wrap onto multiple lines.
- `justify`: defines how the browser distributes space between and around content items along the main axis of a flex container.
- `align`: it controls the alignment of items on the cross axis.
- `direction`: sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed).
- `className`: Custom CSS class names

## Anatomy

Import all parts and piece them together.

<LiveProvider>
<LiveEditor code={`
import { Flex } from '@raystack/apsara/v1'
<Flex direction="column" justify="center">
<Flex direction="row" gap="medium"></Flex>
<Flex direction="row" align="center"></Flex>
</Flex>
`} border />

</LiveProvider>
64 changes: 48 additions & 16 deletions apps/www/content/primitives/components/text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Text
description:
---

## Preview

<Preview>
Expand All @@ -25,7 +26,7 @@ description:
<Text weight="600">This is a test</Text>
<Text weight="700">This is a test</Text>
<Text weight="800">This is a test</Text>
<Text weight="900">This is a test</Text>
<Text weight="900">This is a test</Text>

</Flex>
</Preview>
Expand All @@ -35,28 +36,59 @@ description:
Install the component from your command line.

<LiveProvider>
<LiveEditor code={`npm install @raystack/apsara`} border/>
<LiveEditor code={`npm install @raystack/apsara`} border />
</LiveProvider>

## Variants

<Preview>
<Flex
style={{
flexDirection: "column",
alignItems: "center",
gap: "8px",
}}
>
<Text variant="primary">primary</Text>
<Text variant="secondary">secondary</Text>
<Text variant="tertiary">tertiary</Text>
<div
style={{
backgroundColor: "var(--rs-background-neutral-tertiary)",
padding: "var(--rs-space-3)",
}}
>
<Text variant="emphasis">emphasis</Text>
</div>
<Text variant="accent">accent</Text>
<Text variant="attention">attention</Text>
<Text variant="danger">danger</Text>
<Text variant="success">success</Text>
</Flex>
</Preview>

## Anatomy

Import all parts and piece them together.

<LiveProvider>
<LiveEditor code={`
import { Command } from '@raystack/apsara'
<Text size="1">This is a test</Text>
<Text size="2">This is a test</Text>
<Text size="3">This is a test</Text>
<Text size="4">This is a test</Text>
<Text size="5">This is a test</Text>
<Text weight="400">This is a test</Text>
<Text weight="500">This is a test</Text>
<Text weight="600">This is a test</Text>
<Text weight="bold">This is a test</Text>
<Text weight="bolder">This is a test</Text>
<Text weight="normal">This is a test</Text>
<Text weight="lighter">This is a test</Text>
import { Text } from '@raystack/apsara/v1'
<Text size="1">This is a test</Text>
<Text size="2">This is a test</Text>
<Text size="3">This is a test</Text>
<Text size="4">This is a test</Text>
<Text size="5">This is a test</Text>
<Text weight="400">This is a test</Text>
<Text weight="500">This is a test</Text>
<Text weight="600">This is a test</Text>
<Text weight="bold">This is a test</Text>
<Text weight="bolder">This is a test</Text>
<Text weight="normal">This is a test</Text>
<Text weight="lighter">This is a test</Text>
<Text variant="secondary">This is a test</Text>
`} border />

</LiveProvider>
43 changes: 36 additions & 7 deletions apps/www/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ export const primitivesRoutes = [
{
label: "Components",
pages: [
{ title: "Avatar", slug: "docs/primitives/components/avatar", newBadge: true, },
{
title: "Avatar",
slug: "docs/primitives/components/avatar",
newBadge: true,
},
{ title: "Badge", slug: "docs/primitives/components/badge" },
{ title: "Breadcrumb", slug: "docs/primitives/components/breadcrumb", newBadge: true, },
{ title: "Button", slug: "docs/primitives/components/button", newBadge: true, },
{
title: "Breadcrumb",
slug: "docs/primitives/components/breadcrumb",
newBadge: true,
},
{
title: "Button",
slug: "docs/primitives/components/button",
newBadge: true,
},
{ title: "Calendar", slug: "docs/primitives/components/calendar" },
{ title: "Command", slug: "docs/primitives/components/command" },
{ title: "Checkbox", slug: "docs/primitives/components/checkbox" },
Expand All @@ -25,10 +37,15 @@ export const primitivesRoutes = [
{
title: "Dropdown Menu",
slug: "docs/primitives/components/dropdownmenu",
newBadge: true
newBadge: true,
},
{ title: "Empty State", slug: "docs/primitives/components/emptystate" },
{ title: "ErrorState", slug: "docs/primitives/components/errorstate" },
{
title: "Flex",
slug: "docs/primitives/components/flex",
newBadge: true,
},
{ title: "Headline", slug: "docs/primitives/components/headline" },
{ title: "Image", slug: "docs/primitives/components/image" },
{ title: "Label", slug: "docs/primitives/components/label" },
Expand All @@ -38,15 +55,27 @@ export const primitivesRoutes = [
{ title: "Select", slug: "docs/primitives/components/select" },
{ title: "Separator", slug: "docs/primitives/components/separator" },
{ title: "Sheet", slug: "docs/primitives/components/sheet" },
{ title: "Spinner", slug: "docs/primitives/components/spinner", newBadge: true, },
{
title: "Spinner",
slug: "docs/primitives/components/spinner",
newBadge: true,
},
{ title: "Switch", slug: "docs/primitives/components/switch" },
{ title: "Tabs", slug: "docs/primitives/components/tabs" },
{ title: "Table", slug: "docs/primitives/components/table" },
{ title: "Text", slug: "docs/primitives/components/text" },
{
title: "Text",
slug: "docs/primitives/components/text",
newBadge: true,
},
{ title: "Text Field", slug: "docs/primitives/components/textfield" },
{ title: "Tooltip", slug: "docs/primitives/components/tooltip" },
{ title: "Toggle Group", slug: "docs/primitives/components/togglegroup" },
{ title: "Toast", slug: "docs/primitives/components/toast", newBadge: true },
{
title: "Toast",
slug: "docs/primitives/components/toast",
newBadge: true,
},
],
},
];
Expand Down
3 changes: 3 additions & 0 deletions packages/raystack/flex/flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const flex = cva(styles.flex, {
type BoxProps = PropsWithChildren<VariantProps<typeof flex>> &
HTMLAttributes<HTMLDivElement>;

/**
* @deprecated Use Flex from '@raystack/apsara/v1' instead.
*/
export const Flex = forwardRef<HTMLDivElement, BoxProps>(
(
{ children, direction, align, justify, wrap, gap, className, ...props },
Expand Down
3 changes: 3 additions & 0 deletions packages/raystack/text/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const text = cva(styles.text, {
export type TextProps = PropsWithChildren<VariantProps<typeof text>> &
HTMLAttributes<HTMLSpanElement>;

/**
* @deprecated Use Text from '@raystack/apsara/v1' instead.
*/
export function Text({
children,
className,
Expand Down
88 changes: 88 additions & 0 deletions packages/raystack/v1/components/flex/flex.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.flex {
box-sizing: border-box;
display: flex;
}

.direction-row {
flex-direction: row;
}

.direction-column {
flex-direction: column;
}

.direction-rowReverse {
flex-direction: row-reverse;
}

.direction-columnReverse {
flex-direction: column-reverse;
}

.align-start {
align-items: flex-start;
}

.align-center {
align-items: center;
}

.align-end {
align-items: flex-end;
}

.align-stretch {
align-items: stretch;
}

.align-baseline {
align-items: baseline;
}

.justify-start {
justify-content: flex-start;
}

.justify-center {
justify-content: center;
}

.justify-end {
justify-content: end;
}

.justify-between {
justify-content: space-between;
}

.wrap-noWrap {
flex-wrap: nowrap;
}

.wrap-wrap {
flex-wrap: wrap;
}

.wrap-wrapReverse {
flex-wrap: wrap-reverse;
}

.gap-xs {
gap: var(--rs-space-2);
}

.gap-sm {
gap: var(--rs-space-3);
}

.gap-md {
gap: var(--rs-space-5);
}

.gap-lg {
gap: var(--rs-space-9);
}

.gap-xl {
gap: var(--rs-space-11);
}
65 changes: 65 additions & 0 deletions packages/raystack/v1/components/flex/flex.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { cva, VariantProps } from "class-variance-authority";
import { forwardRef, HTMLAttributes, PropsWithChildren } from "react";
import styles from "./flex.module.css";

const flex = cva(styles.flex, {
variants: {
direction: {
row: styles["direction-row"],
column: styles["direction-column"],
rowReverse: styles["direction-rowReverse"],
columnReverse: styles["direction-columnReverse"],
},
align: {
start: styles["align-start"],
center: styles["align-center"],
end: styles["align-end"],
stretch: styles["align-stretch"],
baseline: styles["align-baseline"],
},
justify: {
start: styles["justify-start"],
center: styles["justify-center"],
end: styles["justify-end"],
between: styles["justify-between"],
},
wrap: {
noWrap: styles["wrap-noWrap"],
wrap: styles["wrap-wrap"],
wrapReverse: styles["wrap-wrapReverse"],
},
gap: {
"extra-small": styles["gap-xs"],
small: styles["gap-sm"],
medium: styles["gap-md"],
large: styles["gap-lg"],
"extra-large": styles["gap-xl"],
},
},
defaultVariants: {
direction: "row",
align: "stretch",
justify: "start",
wrap: "noWrap",
},
});

type BoxProps = PropsWithChildren<VariantProps<typeof flex>> &
HTMLAttributes<HTMLDivElement>;

export const Flex = forwardRef<HTMLDivElement, BoxProps>(
(
{ children, direction, align, justify, wrap, gap, className, ...props },
ref
) => {
return (
<div
className={flex({ direction, align, justify, wrap, gap, className })}
{...props}
ref={ref}
>
{children}
</div>
);
}
);
1 change: 1 addition & 0 deletions packages/raystack/v1/components/flex/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Flex } from "./flex";
Loading

0 comments on commit 926a89c

Please sign in to comment.