===============
LIBRARY RULES
===============
From library maintainers:
- Use UZH DF design-system components whenever they are available for frontend tasks
- Use theme-based styling with Tailwind CSS
### Default Command Palette Example with Suggestions and Settings (TSX)
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Command.stories.mdx
A practical example of the `Command` component demonstrating a default setup with grouped suggestions and settings. It includes an input, empty state, and items with icons and keyboard shortcuts, showcasing common usage patterns.
```tsx
export const Default = () => {
return (
No results found.CalendarSearch EmojiCalculatorProfile⌘PBilling⌘BSettings⌘S
)
}
```
--------------------------------
### Default Pagination Component Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Pagination.stories.mdx
This example demonstrates the default rendering of the Pagination component, showcasing a standard setup with previous/next buttons, numbered page links, and an ellipsis indicator for skipped pages.
```tsx
export const Default = () => {
return (
1
2
3
)
}
```
--------------------------------
### Basic Tabs Usage
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Tabs.stories.mdx
Example demonstrating the basic setup of the Tabs component with three distinct tab sections.
```tsx
import { useState } from 'react'
import { TabContent, Tabs } from './Tabs'
function ExampleTabs() {
return (
Overview Content
Summary information goes here.
Detailed Information
More specific details about the item.
Settings Panel
Configure options here.
)
}
```
--------------------------------
### Basic Modal Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Modal.stories.mdx
A simple example of a Modal component with only the essential props for opening and closing.
```jsx
export const Basic = () => {
const [isOpen, setIsOpen] = useState(false)
return (
setIsOpen(true)}>Open Modal}
onClose={() => setIsOpen(false)}
>
Consectetur enim adipisicing do culpa. Laborum laboris labore velit
incididunt est do duis in cupidatat proident. Veniam quis ex dolore
pariatur eu. Quis adipisicing aliqua et Lorem minim. Nostrud anim duis
commodo nostrud deserunt adipisicing dolor officia amet non tempor tempor
laboris. Nisi esse voluptate non enim aute nisi nostrud eiusmod laboris.
)
}
```
--------------------------------
### Navigation Handler Examples
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/StepProgress.stories.mdx
Provides examples of different navigation handler functions for various scenarios like form wizards, quiz reviews, and linear process tracking.
```javascript
// Form wizard navigation
const handleStepClick = (step, item) => {
if (step <= completedSteps) {
setCurrentStep(step)
} else {
// Prevent navigation to incomplete steps
showWarning('Please complete current step first')
}
}
// Quiz review navigation
const handleQuizReview = (step, item) => {
setCurrentStep(step)
setReviewMode(true)
loadQuestionData(item.id)
}
// Linear process with status tracking
const handleProcessStep = (step, item) => {
updateStepStatus(currentStep, 'completed')
setCurrentStep(step)
logStepNavigation(step, item)
}
```
--------------------------------
### Simple Table Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Table.stories.mdx
A basic example of rendering a Table component with predefined columns and data.
```jsx
import React from 'react';
import { Table } from './Table'; // Assuming Table component is in './Table'
import { UserNotification } from './UserNotification'; // Assuming UserNotification component is in './UserNotification'
const data = [
{ count: 10, answer: 'Yes', username: 'user1' },
{ count: 5, answer: 'No', username: 'user2' },
{ count: 15, answer: 'Maybe', username: 'user3' },
];
export const SimpleTable = () => (
);
```
--------------------------------
### Default ShadcnProgress Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/ShadcnProgress.stories.mdx
A basic example of the ShadcnProgress component, demonstrating an animated progress bar that transitions from 13% to 66%.
```tsx
import { useState, useEffect } from 'react'
import { ShadcnProgress } from './ShadcnProgress'
export const Default = () => {
const [progress, setProgress] = useState(13)
useEffect(() => {
const timer = setTimeout(() => setProgress(66), 500)
return () => clearTimeout(timer)
}, [])
return
}
```
--------------------------------
### Basic AlertDialog Usage Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/AlertDialog.stories.mdx
A basic example demonstrating the implementation of an AlertDialog component. It shows how to set up a trigger button, define the dialog's header, title, description, and footer with cancel and continue actions.
```tsx
export const Default = () => {
return (
Are you absolutely sure?
This action cannot be undone. This will permanently delete your
account and remove your data from our servers.
CancelContinue
)
}
```
--------------------------------
### Default Dropdown Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Dropdown.stories.mdx
A basic example of the Dropdown component rendering simple clickable menu items.
```jsx
export const Default = () => {
return (
If items are given to the dropdown menu component, they are rendered as
single elements. Any data passed via the groups attribute is ignored and not
displayed.
)
}
```
--------------------------------
### Default ShadcnProgress Component Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/ShadcnProgress.stories.mdx
A basic example demonstrating the `ShadcnProgress` component with a simple animation that updates its value from 13% to 66% after a short delay. This showcases a common pattern for displaying initial loading states or partial progress.
```tsx
import { useState, useEffect } from 'react'
import { ShadcnProgress } from './ShadcnProgress'
export const Default = () => {
const [progress, setProgress] = useState(13)
useEffect(() => {
const timer = setTimeout(() => setProgress(66), 500)
return () => clearTimeout(timer)
}, [])
return
}
```
--------------------------------
### Default Collapsible Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Collapsible.stories.mdx
A simple example demonstrating the default usage of the Collapsible component with basic static and closed content.
```tsx
import React, { useState } from 'react';
// Assuming Collapsible component is imported
// import Collapsible from 'your-library';
export const Default = () => {
const [open, setOpen] = useState(false)
return (
{
setOpen(!open)
}}
staticContent="Static content"
closedContent="Closed content"
>
Dynamic content
)
}
```
--------------------------------
### Card Component Usage Examples
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Card.stories.mdx
Demonstrates various ways to use the Card component, from basic content display to more complex structures like product cards and login forms. Includes examples with CardHeader, CardContent, and CardFooter.
```tsx
import { Button } from './Button'
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from './ui/card'
// Basic content card
Card TitleCard description or subtitle
Main content goes here...
// Simple card without header/footer
Simple Content
Just content with consistent padding.
// Product card example
Product Name$99.99
```
--------------------------------
### ShadcnMenubar Component Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/ShadcnMenubar.stories.mdx
This code snippet demonstrates the full implementation of the ShadcnMenubar component, showcasing various menu items, sub-menus, checkboxes, radio groups, and shortcuts. It serves as a practical example for integrating the component into an application.
```jsx
export const Default = () => {
return (
File
New Tab ⌘T
New Window ⌘NNew Incognito WindowShareEmail linkMessagesNotes
Print... ⌘PEdit
Undo ⌘Z
Redo ⇧⌘ZFindSearch the webFind...Find NextFind PreviousCutCopyPasteView
Always Show Bookmarks Bar
Always Show Full URLs
Reload ⌘R
Force Reload ⇧⌘RToggle FullscreenHide SidebarProfilesAndy
Benoit
LuisEdit...Add Profile...
)
}
```
--------------------------------
### Default NavigationMenu Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/NavigationMenu.stories.mdx
A basic implementation of the NavigationMenu component, showcasing a primary navigation item 'Home' with a dropdown content area. This example demonstrates the core structure for creating navigation hierarchies.
```jsx
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
} from "@/components/ui/navigation-menu"
export const Default = () => {
return (
Home
Re-usable components built using Radix UI and Tailwind
CSS.
>
<>
Installation
How to install dependencies and structure your app.
>
<>
Typography
Styles for headings, paragraphs, lists...etc
>
Components
{[ { title: 'Alert Dialog', /* ... */ } ]}
)
}
```
--------------------------------
### Skeleton Component Usage Examples
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Skeleton.stories.mdx
Demonstrates various ways to use the Skeleton component for different content structures, including text lines, profile cards, general cards, and table rows. Each example shows how to apply CSS classes to define the shape, size, and animation of the placeholders.
```tsx
// Text line skeletons
// Profile card skeleton
// Card skeleton
// Table row skeletons
{Array.from({ length: 5 }).map((_, i) => (
))}
```
--------------------------------
### FullScreen Modal Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Modal.stories.mdx
Illustrates how to render the Modal component in full-screen mode.
```react
import React, { useState } from 'react';
import Modal from './Modal';
function App() {
const [isOpen, setIsOpen] = useState(false);
return (
);
}
export default App;
```
--------------------------------
### Default RadioGroup Story Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/RadioGroup.stories.mdx
A simple example demonstrating the `RadioGroup` component with three predefined options ('default', 'comfortable', 'compact') and associated labels. This snippet showcases the basic rendering and functionality of the component in a typical usage scenario.
```tsx
export const Default = () => {
return (
Default
Comfortable
Compact
)
}
```
--------------------------------
### International Configuration
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/DatetimePicker.stories.mdx
Shows how to configure the DatetimePicker for international use by setting the locale, display format, and the starting day of the week. This example uses German locale and Monday as the start of the week.
```tsx
import React, { useState } from 'react';
// Assuming DatetimePicker component is imported from its module
// import DatetimePicker from './DatetimePicker';
function App() {
const [meetingTime, setMeetingTime] = useState(undefined);
return (
);
}
export default App;
```
--------------------------------
### Basic Step Progress Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/StepProgress.stories.mdx
Demonstrates the basic usage of the StepProgress component with numeric steps and click navigation.
```javascript
import React, { useState } from 'react';
import StepProgress from './StepProgress';
function App() {
const [currentStep, setCurrentStep] = useState(0);
return (
Multi-Step Process
setCurrentStep(step)}
/>
Current Step: {currentStep + 1}
);
}
export default App;
```
--------------------------------
### Basic Workflow Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Workflow.stories.mdx
Demonstrates the basic usage of the Workflow component with clickable steps and active state management using React's useState hook.
```javascript
import { useState } from 'react'
import Workflow from './Workflow'
import {
workflowItemsDescription,
workflowTooltipItems,
workflowItems,
} from './values'
export function Default() {
const [activeIx, setActiveIx] = useState(0)
return (
The workflow component always grows to 100% width of the parent
container and splits the available space evenly between the number of
passed items. If a description is passed, the height of the component
adapts accordingly. Limited custom styling is available. The items can
contain custom data, which is passed back to the onClick handler.
setActiveIx(ix)}
activeIx={activeIx}
/>
)
}
```
--------------------------------
### Basic Drawer Usage Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Drawer.stories.mdx
Demonstrates the basic implementation of the Drawer component, including a trigger button and content with header, description, and footer actions.
```tsx
SettingsAdjust your preferences
Notifications
Dark Mode
```
--------------------------------
### Link Component Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Navigation.stories.mdx
Demonstrates the usage of a 'link' component, including its label, click handler, optional badge, and associated CSS classes.
```javascript
{
key: 'dropdown-menubar-item1',
type: 'link',
label: 'Item 1',
onClick: () => alert('Item 1 clicked'),
notification: true,
}
```
```javascript
{
key: 'dropdown-menubar-item2',
type: 'link',
label: 'Item 2',
onClick: () => alert('Item 2 clicked'),
badge: 'Coming Soon',
className: { badge: 'bg-orange-500 hover:bg-orange-600' },
}
```
```javascript
{
key: 'dropdown-menubar-item3',
type: 'link',
label: 'Item 3',
onClick: () => alert('Item 3 clicked'),
}
```
--------------------------------
### Basic FormikTextareaField Usage
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/forms/FormikTextareaField.stories.mdx
Example of using the FormikTextareaField component within a Formik form for collecting user comments. It demonstrates basic setup with a name, label, and submission handling.
```jsx
import { Form, Formik } from 'formik';
import FormikTextareaField from './FormikTextareaField';
// ... inside your component
console.log(values)}
>
```
--------------------------------
### Required Switch
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/forms/FormikSwitchField.stories.mdx
Illustrates how to make a Switch component mandatory using the 'required' prop. This example shows the basic setup for a required switch within a Formik form, including submission handling.
```jsx
export const Required = () => {
return (
{
alert(`Switch value: ${values.switch}`)
}}
>
{({ values }) => {
return (
)
}}
)
}
```
--------------------------------
### Render Compact ShadcnTable Structure in TSX
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/ShadcnTable.stories.mdx
Shows a simple, compact `ShadcnTable` structure with a header and initial columns, suitable for displaying concise data sets. This example provides a minimal setup for a table.
```tsx
// Compact table
IDTask
```
--------------------------------
### Basic Button Navigation Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Navigation.stories.mdx
Demonstrates how to use the Navigation component with basic button items, including setting labels, click handlers, and active states.
```tsx
import Navigation from './Navigation';
// Assuming 'navigate' is a function for routing
const MyNavigation = () => (
navigate('/home'),
active: true
},
{
type: 'button',
key: 'about',
label: 'About',
onClick: () => navigate('/about')
}
]}
/>
);
```
--------------------------------
### Event Scheduling with FormikDatetimePicker
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/forms/FormikDatetimePicker.stories.mdx
Demonstrates scheduling an event with start and end times, including validation to ensure the start time is in the future and the end time is after the start time.
```tsx
import React from 'react';
import { Formik, Form } from 'formik';
import * as Yup from 'yup';
import FormikDatetimePicker from './FormikDatetimePicker'; // Assuming FormikDatetimePicker is in the same directory
import Button from './Button'; // Assuming Button component exists
const handleEventCreation = (values) => {
console.log('Event created:', values);
};
const EventSchedulingForm = () => {
return (
);
};
export default EventSchedulingForm;
```
--------------------------------
### Basic Sidebar Usage Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Sidebar.stories.mdx
Demonstrates a basic implementation of the Sidebar component with header, grouped navigation, and main content.
```tsx
```
--------------------------------
### Default Checkbox Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Checkbox.stories.mdx
A basic example of a Checkbox component with its state managed by `useState`.
```tsx
export const Default = () => {
const [isChecked, setIsChecked] = useState(true)
return (
setIsChecked(!isChecked)} />
)
}
```
--------------------------------
### CycleProgress Component Usage Examples
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/CycleProgress.stories.mdx
Demonstrates various ways to use the CycleProgress component, including basic usage, different size variants, custom colors, and integrating custom content.
```jsx
import CycleProgress from './CycleProgress';
// Basic progress indicator
75%
// Small size variant
45%
// Custom color and styling
```
--------------------------------
### Default Countdown Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Countdown.stories.mdx
A basic example demonstrating how to use the Countdown component with an expiration time.
```jsx
export const Default = () => {
const time = new Date()
time.setSeconds(time.getSeconds() + 40)
return
}
```
--------------------------------
### FormikColorPicker - Default Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/forms/FormikColorPicker.stories.mdx
A basic example of using the FormikColorPicker with a single color field and a submit button.
```jsx
import {
Formik
} from 'formik';
import {
FormikColorPicker
} from './FormikColorPicker'; // Assuming path to component
import {
Form
} from './Form'; // Assuming Form component exists
export const Default = () => (
{
alert(
`Form submitted with color: ${values.color}. The form will be reset.`
)
resetForm()
}}
>
{({ values }) => {
return (
)
}}
)
```
--------------------------------
### CycleProgress Component Examples
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/CycleProgress.stories.mdx
Demonstrates various ways to use the CycleProgress component, including default usage, small size, custom colors, and overriding default sizing.
```jsx
export function Default() {
return 60
}
```
```jsx
export function Small() {
return (
60
)
}
```
```jsx
export function Colored() {
return (
60
)
}
```
```jsx
export function OverrideSize() {
return (
Depending on the type of font that was chosen, it is possible that the
text does not appear centered. In this case, it might be necessary to
override the size, which is set manually. However, this is explicitely set
as an override to only be used when necessary. Whenever an override is
used, the className root will probably also have to be adapted accordingly
60
)
}
```
--------------------------------
### Basic User Notification Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/UserNotification.stories.mdx
A simple example of the UserNotification component displaying an informational message.
```tsx
import UserNotification from './UserNotification';
// ... inside a React component
```
--------------------------------
### Header Component Usage Examples
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/Header.stories.mdx
Demonstrates various ways to use the Header components, including basic usage, custom styling, testing attributes, and integration into document structure.
```tsx
import Header from './Header';
// Page title
Welcome to Our Application
// Section heading
Getting Started
// Subsection
Installation Steps
// Minor section
Prerequisites
// With custom styling
Custom Styled Heading
// With testing attributes
Testable Section Heading
// Document structure example
Article TitleIntroduction
Article introduction...
Key Points
Important information...
Details
Detailed explanation...
Conclusion
Final thoughts...
// Dynamic heading levels
const HeadingComponent = ({ level, children }) => {
const HeadingTag = Header[`H${level}`]
return {children}
}
Dynamic Heading
// With complex content
Section:{" "}
User Management
// Form section headers
// Navigation integration
```
--------------------------------
### Account Recovery PIN Example
Source: https://github.com/uzh-bf/design-system/blob/main/packages/design-system/src/forms/FormikPinField.stories.mdx
Provides an example of using FormikPinField for account recovery, including a descriptive header and tooltip.
```tsx
import { Form, Formik } from 'formik';
import FormikPinField from './FormikPinField';
// Account recovery PIN
```