Skip to content

The Open Standard for Generative UI

Split steps component into separate component Steps and steps-item

subhamed51e4a65dd7
diff --git a/js/packages/react-ui/package.json b/js/packages/react-ui/package.json
index 44771660a..10cc4566d 100644
--- a/js/packages/react-ui/package.json
+++ b/js/packages/react-ui/package.json
@@ -2,7 +2,7 @@
"type": "module",
"name": "@crayonai/react-ui",
"license": "MIT",
- "version": "0.5.10",
+ "version": "0.5.11",
"description": "Component library for Generative UI SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/js/packages/react-ui/src/components/CheckBoxGroup/checkBoxGroup.scss b/js/packages/react-ui/src/components/CheckBoxGroup/checkBoxGroup.scss
index 118baca16..3126b1c1d 100644
--- a/js/packages/react-ui/src/components/CheckBoxGroup/checkBoxGroup.scss
+++ b/js/packages/react-ui/src/components/CheckBoxGroup/checkBoxGroup.scss
@@ -4,7 +4,7 @@
box-sizing: border-box;
display: flex;
flex-direction: column;
- gap: cssUtils.$spacing-2xs;
+ gap: cssUtils.$spacing-3xs;
border: 1px solid;
border-radius: cssUtils.$rounded-m;
diff --git a/js/packages/react-ui/src/components/CheckBoxItem/checkBoxItem.scss b/js/packages/react-ui/src/components/CheckBoxItem/checkBoxItem.scss
index ea12fb0b6..2a3a179d4 100644
--- a/js/packages/react-ui/src/components/CheckBoxItem/checkBoxItem.scss
+++ b/js/packages/react-ui/src/components/CheckBoxItem/checkBoxItem.scss
@@ -3,7 +3,7 @@
.crayon-checkbox-item-container {
display: flex;
align-items: center;
- gap: cssUtils.$spacing-2xs;
+ gap: cssUtils.$spacing-xs;
width: 100%;
max-width: 100%;
overflow: hidden;
@@ -24,6 +24,11 @@
background-color: cssUtils.$bg-container;
cursor: pointer;
+ &[data-state="checked"] {
+ background-color: cssUtils.$bg-brand-el;
+ color: cssUtils.$primary-text;
+ }
+
&:not(:disabled):hover {
border-color: cssUtils.$stroke-interactive-el-hover;
}
@@ -38,7 +43,7 @@
display: flex;
align-items: center;
justify-content: center;
- color: cssUtils.$primary-text;
+ color: cssUtils.$brand-text;
}
.crayon-checkbox-item-label {
diff --git a/js/packages/react-ui/src/components/FormControl/formControl.scss b/js/packages/react-ui/src/components/FormControl/formControl.scss
index 70f375fb1..dc6718724 100644
--- a/js/packages/react-ui/src/components/FormControl/formControl.scss
+++ b/js/packages/react-ui/src/components/FormControl/formControl.scss
@@ -5,5 +5,5 @@
box-sizing: border-box;
display: flex;
flex-direction: column;
- gap: cssUtils.$spacing-xs;
+ gap: cssUtils.$spacing-s;
}
diff --git a/js/packages/react-ui/src/components/Input/Input.tsx b/js/packages/react-ui/src/components/Input/Input.tsx
index d19d99b68..22c73e15d 100644
--- a/js/packages/react-ui/src/components/Input/Input.tsx
+++ b/js/packages/react-ui/src/components/Input/Input.tsx
@@ -17,6 +17,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, styles, size = "medium", ...props }, ref) => {
return (
<input
+ autoComplete="off"
ref={ref}
className={clsx("crayon-input", sizes[size], className)}
style={styles}
diff --git a/js/packages/react-ui/src/components/RadioGroup/radioGroup.scss b/js/packages/react-ui/src/components/RadioGroup/radioGroup.scss
index 495a5dcb2..09b4a3820 100644
--- a/js/packages/react-ui/src/components/RadioGroup/radioGroup.scss
+++ b/js/packages/react-ui/src/components/RadioGroup/radioGroup.scss
@@ -4,7 +4,7 @@
box-sizing: border-box;
display: flex;
flex-direction: column;
- gap: cssUtils.$spacing-s;
+ gap: cssUtils.$spacing-3xs;
border: 1px solid;
border-radius: cssUtils.$rounded-m;
diff --git a/js/packages/react-ui/src/components/RadioItem/radioItem.scss b/js/packages/react-ui/src/components/RadioItem/radioItem.scss
index fe7d2431f..080e9a860 100644
--- a/js/packages/react-ui/src/components/RadioItem/radioItem.scss
+++ b/js/packages/react-ui/src/components/RadioItem/radioItem.scss
@@ -3,7 +3,7 @@
.crayon-radio-item-container {
display: flex;
align-items: center;
- gap: cssUtils.$spacing-2xs;
+ gap: cssUtils.$spacing-xs;
padding-top: cssUtils.$spacing-3xs;
padding-bottom: cssUtils.$spacing-3xs;
padding-left: cssUtils.$spacing-0;
diff --git a/js/packages/react-ui/src/components/Steps/Steps.tsx b/js/packages/react-ui/src/components/Steps/Steps.tsx
index 61c2be270..f9feea9e7 100644
--- a/js/packages/react-ui/src/components/Steps/Steps.tsx
+++ b/js/packages/react-ui/src/components/Steps/Steps.tsx
@@ -1,33 +1,43 @@
-import React from "react";
+import React, { createContext, useContext } from "react";
-export interface Step {
+export interface StepsItemProps {
title: React.ReactNode;
details: React.ReactNode;
}
export interface StepsProps {
- steps: Step[];
+ children: React.ReactNode;
}
-export const Steps: React.FC<StepsProps> = ({ steps }) => {
+const StepNumberContext = createContext<number>(0);
+
+export const Steps: React.FC<StepsProps> = ({ children }) => {
return (
<div className={`crayon-steps-container`}>
<div className="crayon-steps">
- {steps.map((step, index) => (
- <div key={index} className={`crayon-step-item`}>
- <div className="crayon-step-connector">
- <div className="crayon-step-number">
- <div className="crayon-step-number-inner">{index + 1}</div>
- </div>
- {index < steps.length - 1 && <div className="crayon-connector-line" />}
- </div>
- <div className="crayon-step-content">
- <span className="crayon-step-title">{step.title}</span>
- <div className="crayon-step-details">{step.details}</div>
- </div>
- </div>
+ {React.Children.map(children, (child, index) => (
+ <StepNumberContext.Provider value={index + 1}>{child}</StepNumberContext.Provider>
))}
</div>
</div>
);
};
+
+export const StepsItem: React.FC<StepsItemProps> = ({ title, details }) => {
+ const stepNumber = useContext(StepNumberContext);
+
+ return (
+ <div className="crayon-step-item">
+ <div className="crayon-step-connector">
+ <div className="crayon-step-number">
+ <div className="crayon-step-number-inner">{stepNumber}</div>
+ </div>
+ <div className="crayon-connector-line" />
+ </div>
+ <div className="crayon-step-content">
+ <span className="crayon-step-title">{title}</span>
+ <div className="crayon-step-details">{details}</div>
+ </div>
+ </div>
+ );
+};
diff --git a/js/packages/react-ui/src/components/Steps/steps.scss b/js/packages/react-ui/src/components/Steps/steps.scss
index 7ae063368..74a6ea48c 100644
--- a/js/packages/react-ui/src/components/Steps/steps.scss
+++ b/js/packages/react-ui/src/components/Steps/steps.scss
@@ -4,8 +4,6 @@
min-width: 280px;
width: 100%;
margin: 0 auto;
- @include cssUtils.typography(label, small);
- color: cssUtils.$primary-text;
}
.crayon-steps {
@@ -16,14 +14,13 @@
.crayon-step-item {
display: flex;
position: relative;
- color: cssUtils.$primary-text;
+ gap: cssUtils.$spacing-s;
}
.crayon-step-connector {
display: flex;
flex-direction: column;
align-items: center;
- margin-right: cssUtils.$spacing-xs;
}
.crayon-step-number {
@@ -31,9 +28,7 @@
display: flex;
align-items: center;
justify-content: center;
- @include cssUtils.typography(label, default);
z-index: 2;
- color: cssUtils.$secondary-text;
}
.crayon-step-number-inner {
@@ -43,10 +38,11 @@
width: 20px;
height: 20px;
border-radius: 50%;
- background-color: cssUtils.$bg-sunk;
+ background-color: cssUtils.$bg-elevated;
color: cssUtils.$secondary-text;
border: 1px solid cssUtils.$stroke-default;
box-sizing: border-box;
+ @include cssUtils.typography(label, default);
}
.crayon-connector-line {
@@ -54,6 +50,10 @@
flex-grow: 1;
z-index: 1;
background-color: cssUtils.$bg-container-hover;
+
+ .crayon-step-item:last-child & {
+ display: none;
+ }
}
.crayon-step-content {
diff --git a/js/packages/react-ui/src/components/Steps/stories/steps.stories.tsx b/js/packages/react-ui/src/components/Steps/stories/steps.stories.tsx
index 6b5ba130f..79edf6a91 100644
--- a/js/packages/react-ui/src/components/Steps/stories/steps.stories.tsx
+++ b/js/packages/react-ui/src/components/Steps/stories/steps.stories.tsx
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Card } from "../../Card";
-import { Steps, StepsProps } from "../Steps";
+import { Steps, StepsItem, StepsProps } from "../Steps";
const stepsData = [
{
@@ -32,20 +32,19 @@ const meta: Meta<StepsProps> = {
layout: "centered",
docs: {
description: {
- component: "```tsx\nimport { Steps } from '@crayon-ui/react-ui';\n```",
+ component: "```tsx\nimport { Steps, StepsItem } from '@crayon-ui/react-ui';\n```",
},
},
},
tags: ["!dev", "autodocs"],
argTypes: {
- steps: {
+ children: {
control: false,
- description:
- "Array of step objects containing title and details. Title is a string and details is a React Node.",
+ description: "StepsItem components to be rendered",
table: {
category: "Content",
- type: { summary: "Step[]" },
- defaultValue: { summary: "[]" },
+ type: { summary: "React.ReactNode" },
+ defaultValue: { summary: "undefined" },
required: true,
},
},
@@ -57,12 +56,13 @@ type Story = StoryObj<typeof meta>;
export const StepsStory: Story = {
name: "Steps",
- args: {
- steps: stepsData,
- },
- render: (args) => (
+ render: () => (
<Card style={{ width: "500px" }}>
- <Steps {...args} />
+ <Steps>
+ {stepsData.map((step, index) => (
+ <StepsItem key={index} {...step} />
+ ))}
+ </Steps>
</Card>
),
parameters: {
@@ -89,7 +89,11 @@ const steps = [
];
<Card style={{ width: "500px" }}>
- <Steps steps={steps} />
+ <Steps>
+ {steps.map((step, index) => (
+ <StepsItem key={index} title={step.title} details={step.details} />
+ ))}
+ </Steps>
</Card>`,
},
},
diff --git a/js/packages/react-ui/src/components/SwitchGroup/switchGroup.scss b/js/packages/react-ui/src/components/SwitchGroup/switchGroup.scss
index 6df85f27b..2bf0b3a1c 100644
--- a/js/packages/react-ui/src/components/SwitchGroup/switchGroup.scss
+++ b/js/packages/react-ui/src/components/SwitchGroup/switchGroup.scss
@@ -4,7 +4,7 @@
box-sizing: border-box;
display: flex;
flex-direction: column;
- gap: cssUtils.$spacing-2xs;
+ gap: cssUtils.$spacing-3xs;
border: 1px solid;
border-radius: cssUtils.$rounded-m;
diff --git a/js/packages/react-ui/src/components/SwitchItem/switchItem.scss b/js/packages/react-ui/src/components/SwitchItem/switchItem.scss
index e17ce63ca..97f7ef0b3 100644
--- a/js/packages/react-ui/src/components/SwitchItem/switchItem.scss
+++ b/js/packages/react-ui/src/components/SwitchItem/switchItem.scss
@@ -4,7 +4,7 @@
box-sizing: border-box;
display: flex;
align-items: center;
- gap: cssUtils.$spacing-2xs;
+ gap: cssUtils.$spacing-xs;
max-width: 100%;
width: 100%;
overflow: hidden;
diff --git a/js/packages/react-ui/src/components/Tabs/Tabs.tsx b/js/packages/react-ui/src/components/Tabs/Tabs.tsx
index 56561c0f9..cf1d4de49 100644
--- a/js/packages/react-ui/src/components/Tabs/Tabs.tsx
+++ b/js/packages/react-ui/src/components/Tabs/Tabs.tsx
@@ -1,6 +1,8 @@
import * as TabsPrimitive from "@radix-ui/react-tabs";
import clsx from "clsx";
-import React, { forwardRef } from "react";
+import { ArrowLeft, ArrowRight } from "lucide-react";
+import React, { forwardRef, useEffect, useRef, useState } from "react";
+import { IconButton } from "../IconButton";
type TabsVariant = "clear" | "card" | "sunk";
@@ -33,14 +35,98 @@ export interface TabsListProps extends React.ComponentPropsWithoutRef<typeof Tab
}
export const TabsList = forwardRef<React.ComponentRef<typeof TabsPrimitive.List>, TabsListProps>(
- ({ className, style, ...props }, ref) => (
- <TabsPrimitive.List
- ref={ref}
- className={clsx("crayon-tabs-list", className)}
- style={style}
- {...props}
- />
- ),
+ ({ className, style, ...props }, ref) => {
+ const listRef = useRef<HTMLDivElement>(null);
+ const [showLeftButton, setShowLeftButton] = useState(false);
+ const [showRightButton, setShowRightButton] = useState(false);
+
+ // Check if scrolling is needed
+ useEffect(() => {
+ const checkScroll = () => {
+ if (listRef.current) {
+ const { scrollLeft, scrollWidth, clientWidth } = listRef.current;
+ setShowLeftButton(scrollLeft > 0);
+ setShowRightButton(scrollLeft < scrollWidth - clientWidth - 1); // -1 for rounding errors
+ }
+ };
+
+ // Initial check
+ checkScroll();
+
+ // Add event listener for scroll
+ const currentRef = listRef.current;
+ if (currentRef) {
+ currentRef.addEventListener("scroll", checkScroll);
+
+ // Also add resize observer to handle responsive changes
+ const resizeObserver = new ResizeObserver(checkScroll);
+ resizeObserver.observe(currentRef);
+
+ return () => {
+ currentRef.removeEventListener("scroll", checkScroll);
+ resizeObserver.disconnect();
+ };
+ }
+ return () => {};
+ }, []);
+
+ // Scroll functions
+ const scrollLeft = () => {
+ if (listRef.current) {
+ // Scroll one tab to the left
+ listRef.current.scrollBy({ left: -120, behavior: "smooth" });
+ }
+ };
+
+ const scrollRight = () => {
+ if (listRef.current) {
+ // Scroll one tab to the right
+ listRef.current.scrollBy({ left: 120, behavior: "smooth" });
+ }
+ };
+
+ return (
+ <div className="crayon-tabs-list-container">
+ {showLeftButton && (
+ <IconButton
+ className="crayon-tabs-scroll-button crayon-tabs-scroll-left"
+ onClick={scrollLeft}
+ aria-label="Scroll tabs left"
+ icon={<ArrowLeft />}
+ variant="secondary"
+ size="small"
+ />
+ )}
+
+ <TabsPrimitive.List
+ ref={(node) => {
+ // Forward the ref to the original ref prop if provided
+ if (typeof ref === "function") {
+ ref(node);
+ } else if (ref) {
+ ref.current = node;
+ }
+ // Also store it in our local ref
+ listRef.current = node;
+ }}
+ className={clsx("crayon-tabs-list", className)}
+ style={style}
+ {...props}
+ />
+
+ {showRightButton && (
+ <IconButton
+ className="crayon-tabs-scroll-button crayon-tabs-scroll-right"
+ onClick={scrollRight}
+ aria-label="Scroll tabs right"
+ icon={<ArrowRight />}
+ variant="secondary"
+ size="small"
+ />
+ )}
+ </div>
+ );
+ },
);
export interface TabsTriggerProps
diff --git a/js/packages/react-ui/src/components/Tabs/tabs.scss b/js/packages/react-ui/src/components/Tabs/tabs.scss
index c749e6177..cd6d0eb9f 100644
--- a/js/packages/react-ui/src/components/Tabs/tabs.scss
+++ b/js/packages/react-ui/src/components/Tabs/tabs.scss
@@ -29,18 +29,44 @@
}
}
+.crayon-tabs-list-container {
+ position: relative;
+ display: flex;
+ align-items: center;
+}
+
+.crayon-tabs-scroll-button {
+ position: absolute;
+ z-index: 1;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ cursor: pointer;
+
+ &.crayon-tabs-scroll-left {
+ left: 2px;
+ }
+
+ &.crayon-tabs-scroll-right {
+ right: 2px;
+ }
+}
+
.crayon-tabs-list {
+ width: 100%;
box-sizing: border-box;
display: flex;
flex-direction: row;
gap: cssUtils.$spacing-s;
- border: 1px solid cssUtils.$stroke-default;
padding: cssUtils.$spacing-2xs;
+ padding-left: cssUtils.$spacing-xs;
+ padding-right: cssUtils.$spacing-xs;
border-radius: cssUtils.$rounded-s;
- background-color: transparent;
+ background-color: cssUtils.$bg-sunk;
overflow-x: auto;
scrollbar-width: none;
-ms-overflow-style: none;
+ scroll-behavior: smooth;
&::-webkit-scrollbar {
display: none;
}
@@ -53,7 +79,7 @@
justify-content: center;
gap: cssUtils.$spacing-2xs;
box-sizing: border-box;
- padding: cssUtils.$spacing-2xs cssUtils.$spacing-3xs;
+ padding: cssUtils.$spacing-2xs cssUtils.$spacing-s cssUtils.$spacing-2xs cssUtils.$spacing-2xs;
border: 1px solid transparent;
border-radius: cssUtils.$rounded-xs;
min-width: 7.3rem;
@@ -62,7 +88,7 @@
color: cssUtils.$secondary-text;
@include cssUtils.typography(label, default);
&[data-state="active"] {
- background-color: cssUtils.$bg-sunk;
+ background-color: cssUtils.$bg-elevated;
border-color: cssUtils.$stroke-default;
color: cssUtils.$primary-text;
}
diff --git a/js/packages/react-ui/src/components/Tag/tag.scss b/js/packages/react-ui/src/components/Tag/tag.scss
index 9f0d9d9a6..55b8568d6 100644
--- a/js/packages/react-ui/src/components/Tag/tag.scss
+++ b/js/packages/react-ui/src/components/Tag/tag.scss
@@ -9,15 +9,15 @@
height: auto;
border: 1px solid cssUtils.$stroke-default;
border-radius: cssUtils.$rounded-s;
- padding: cssUtils.$spacing-2xs cssUtils.$spacing-xs;
- background: cssUtils.$bg-sunk;
+ padding: cssUtils.$spacing-2xs cssUtils.$spacing-s cssUtils.$spacing-2xs cssUtils.$spacing-2xs;
+ background: cssUtils.$bg-elevated;
color: cssUtils.$primary-text;
@include cssUtils.typography(body, default);
+ gap: cssUtils.$spacing-2xs;
&-icon {
display: flex;
align-items: center;
- margin-right: cssUtils.$spacing-3xs;
}
&-text {
diff --git a/js/packages/react-ui/src/components/ThemeProvider/ThemeProvider.tsx b/js/packages/react-ui/src/components/ThemeProvider/ThemeProvider.tsx
index d6b3ba0d1..4af17eaa3 100644
--- a/js/packages/react-ui/src/components/ThemeProvider/ThemeProvider.tsx
+++ b/js/packages/react-ui/src/components/ThemeProvider/ThemeProvider.tsx
@@ -20,6 +20,7 @@ const lightTheme: ColorTheme = {
dangerFills: "rgba(217, 45, 32, 0.08)",
successFills: "rgba(7, 148, 85, 0.08)",
infoFills: "rgba(56, 148, 255, 0.08)",
+ elevatedFills: "rgba(255, 255, 255, 0.3)",
// Border colors
strokeDefault: "rgba(0, 0, 0, 0.06)",
@@ -51,6 +52,7 @@ const darkTheme: ColorTheme = {
dangerFills: "rgba(217, 45, 32, 0.1)",
successFills: "rgba(7, 148, 85, 0.1)",
infoFills: "rgba(56, 148, 255, 0.1)",
+ elevatedFills: "rgba(255, 255, 255, 0.1)",
// Border colors
strokeDefault: "rgba(255, 255, 255, 0.06)",
@@ -220,6 +222,7 @@ export const ThemeProvider = ({
--crayon-danger-fills: ${theme.dangerFills};
--crayon-success-fills: ${theme.successFills};
--crayon-info-fills: ${theme.infoFills};
+ --crayon-elevated-fills: ${theme.elevatedFills};
--crayon-stroke-default: ${theme.strokeDefault};
--crayon-stroke-interactive-el: ${theme.strokeInteractiveEl};
diff --git a/js/packages/react-ui/src/components/ThemeProvider/types.ts b/js/packages/react-ui/src/components/ThemeProvider/types.ts
index 5866deab7..b77684cdd 100644
--- a/js/packages/react-ui/src/components/ThemeProvider/types.ts
+++ b/js/packages/react-ui/src/components/ThemeProvider/types.ts
@@ -14,6 +14,7 @@ export interface ColorTheme {
dangerFills?: string;
successFills?: string;
infoFills?: string;
+ elevatedFills?: string;
// Border colors
strokeDefault?: string;
strokeInteractiveEl?: string;
diff --git a/js/packages/react-ui/src/cssUtils.scss b/js/packages/react-ui/src/cssUtils.scss
index 84ce40cb5..2b8e89ae1 100644
--- a/js/packages/react-ui/src/cssUtils.scss
+++ b/js/packages/react-ui/src/cssUtils.scss
@@ -12,6 +12,7 @@ $bg-sunk: var(--crayon-sunk-fills);
$bg-danger: var(--crayon-danger-fills);
$bg-success: var(--crayon-success-fills);
$bg-info: var(--crayon-info-fills);
+$bg-elevated: var(--crayon-elevated-fills);
// Crayon Stroke Colors