Skip to content

Commit

Permalink
add Card, Alert, Slider, Switch (#990)
Browse files Browse the repository at this point in the history
* add Card, Alert, Slider, Switch

* fix imports

* run build

* add examples to the preview app
  • Loading branch information
Sebastian-ubs authored Jul 12, 2024
1 parent de550a1 commit d584028
Show file tree
Hide file tree
Showing 14 changed files with 3,969 additions and 2,544 deletions.
677 changes: 447 additions & 230 deletions lib/platform-bible-react/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-react/dist/index.cjs.map

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions lib/platform-bible-react/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { AutocompleteChangeDetails, AutocompleteChangeReason, AutocompleteValue, SnackbarCloseReason, SnackbarOrigin } from '@mui/material';
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
import * as SliderPrimitive from '@radix-ui/react-slider';
import * as SwitchPrimitives from '@radix-ui/react-switch';
import * as TabsPrimitive from '@radix-ui/react-tabs';
import { VariantProps } from 'class-variance-authority';
import React$1 from 'react';
Expand Down Expand Up @@ -1143,5 +1145,23 @@ export declare const VerticalTabsTrigger: React$1.ForwardRefExoticComponent<Omit
export declare const VerticalTabsContent: React$1.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsContentProps & React$1.RefAttributes<HTMLDivElement>, "ref"> & {
className?: string | undefined;
} & React$1.RefAttributes<HTMLDivElement>>;
export declare const Card: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
export declare const CardHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
export declare const CardTitle: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLHeadingElement> & React$1.RefAttributes<HTMLParagraphElement>>;
export declare const CardDescription: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLParagraphElement> & React$1.RefAttributes<HTMLParagraphElement>>;
export declare const CardContent: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
export declare const CardFooter: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & React$1.RefAttributes<HTMLDivElement>>;
export declare const Alert: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLDivElement> & VariantProps<(props?: ({
variant?: "default" | "destructive" | null | undefined;
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string> & React$1.RefAttributes<HTMLDivElement>>;
export declare const AlertTitle: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLHeadingElement> & React$1.RefAttributes<HTMLParagraphElement>>;
export declare const AlertDescription: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLParagraphElement> & React$1.RefAttributes<HTMLParagraphElement>>;
declare const Slider$1: React$1.ForwardRefExoticComponent<Omit<SliderPrimitive.SliderProps & React$1.RefAttributes<HTMLSpanElement>, "ref"> & React$1.RefAttributes<HTMLSpanElement>>;
declare const Switch$1: React$1.ForwardRefExoticComponent<Omit<SwitchPrimitives.SwitchProps & React$1.RefAttributes<HTMLButtonElement>, "ref"> & React$1.RefAttributes<HTMLButtonElement>>;

export {
Slider$1 as ShadCnSlider,
Switch$1 as ShadCnSwitch,
};

export {};
4,976 changes: 2,666 additions & 2,310 deletions lib/platform-bible-react/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-react/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/platform-bible-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"@mui/material": ">=5.15.10",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slider": "^1.2.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.1.0",
"@radix-ui/react-tabs": "^1.0.4",
"autoprefixer": "^10.4.19",
"class-variance-authority": "^0.7.0",
Expand Down
52 changes: 52 additions & 0 deletions lib/platform-bible-react/src/components/shadcn-ui/alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { cva, type VariantProps } from 'class-variance-authority';

import { cn } from '@/utils/shadcn-ui.util';

const alertVariants = cva(
'pr-relative pr-w-full pr-rounded-lg pr-border pr-p-4 [&>svg~*]:pr-pl-7 [&>svg+div]:pr-translate-y-[-3px] [&>svg]:pr-absolute [&>svg]:pr-left-4 [&>svg]:pr-top-4 [&>svg]:pr-text-foreground',
{
variants: {
variant: {
default: 'pr-bg-background pr-text-foreground',
destructive:
'pr-border-destructive/50 pr-text-destructive dark:pr-border-destructive [&>svg]:pr-text-destructive',
},
},
defaultVariants: {
variant: 'default',
},
},
);

const Alert = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
>(({ className, variant, ...props }, ref) => (
<div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} />
));
Alert.displayName = 'Alert';

const AlertTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(
({ className, ...props }, ref) => (
<h5
ref={ref}
className={cn('pr-mb-1 pr-font-medium pr-leading-none pr-tracking-tight', className)}
{...props}
>
{/* added because of https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/heading-has-content.md */}
{props.children}{' '}
</h5>
),
);
AlertTitle.displayName = 'AlertTitle';

const AlertDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn('pr-text-sm [&_p]:pr-leading-relaxed', className)} {...props} />
));
AlertDescription.displayName = 'AlertDescription';

export { Alert, AlertTitle, AlertDescription };
66 changes: 66 additions & 0 deletions lib/platform-bible-react/src/components/shadcn-ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';

import { cn } from '@/utils/shadcn-ui.util';

const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
'pr-rounded-lg pr-border pr-bg-card pr-text-card-foreground pr-shadow-sm',
className,
)}
{...props}
/>
),
);
Card.displayName = 'Card';

const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn('pr-flex pr-flex-col pr-space-y-1.5 pr-p-6', className)}
{...props}
/>
),
);
CardHeader.displayName = 'CardHeader';

const CardTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(
({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn('pr-text-2xl pr-font-semibold pr-leading-none pr-tracking-tight', className)}
{...props}
>
{/* added because of https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/heading-has-content.md */}
{props.children}
</h3>
),
);
CardTitle.displayName = 'CardTitle';

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p ref={ref} className={cn('pr-text-sm pr-text-muted-foreground', className)} {...props} />
));
CardDescription.displayName = 'CardDescription';

const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('pr-p-6 pr-pt-0', className)} {...props} />
),
);
CardContent.displayName = 'CardContent';

const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('pr-flex pr-items-center pr-p-6 pr-pt-0', className)} {...props} />
),
);
CardFooter.displayName = 'CardFooter';

export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
26 changes: 26 additions & 0 deletions lib/platform-bible-react/src/components/shadcn-ui/slider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import * as SliderPrimitive from '@radix-ui/react-slider';

import { cn } from '@/utils/shadcn-ui.util';

const Slider = React.forwardRef<
React.ElementRef<typeof SliderPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
>(({ className, ...props }, ref) => (
<SliderPrimitive.Root
ref={ref}
className={cn(
'pr-relative pr-flex pr-w-full pr-touch-none pr-select-none pr-items-center',
className,
)}
{...props}
>
<SliderPrimitive.Track className="pr-relative pr-h-2 pr-w-full pr-grow pr-overflow-hidden pr-rounded-full pr-bg-secondary">
<SliderPrimitive.Range className="pr-absolute pr-h-full pr-bg-primary" />
</SliderPrimitive.Track>
<SliderPrimitive.Thumb className="pr-block pr-h-5 pr-w-5 pr-rounded-full pr-border-2 pr-border-primary pr-bg-background pr-ring-offset-background pr-transition-colors focus-visible:pr-outline-none focus-visible:pr-ring-2 focus-visible:pr-ring-ring focus-visible:pr-ring-offset-2 disabled:pr-pointer-events-none disabled:pr-opacity-50" />
</SliderPrimitive.Root>
));
Slider.displayName = SliderPrimitive.Root.displayName;

export { Slider };
27 changes: 27 additions & 0 deletions lib/platform-bible-react/src/components/shadcn-ui/switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import * as SwitchPrimitives from '@radix-ui/react-switch';

import { cn } from '@/utils/shadcn-ui.util';

const Switch = React.forwardRef<
React.ElementRef<typeof SwitchPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
className={cn(
'pr-peer pr-inline-flex pr-h-6 pr-w-11 pr-shrink-0 pr-cursor-pointer pr-items-center pr-rounded-full pr-border-2 pr-border-transparent pr-transition-colors focus-visible:pr-outline-none focus-visible:pr-ring-2 focus-visible:pr-ring-ring focus-visible:pr-ring-offset-2 focus-visible:pr-ring-offset-background disabled:pr-cursor-not-allowed disabled:pr-opacity-50 data-[state=checked]:pr-bg-primary data-[state=unchecked]:pr-bg-input',
className,
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb
className={cn(
'pr-pointer-events-none pr-block pr-h-5 pr-w-5 pr-rounded-full pr-bg-background pr-shadow-lg pr-ring-0 pr-transition-transform data-[state=checked]:pr-translate-x-5 data-[state=unchecked]:pr-translate-x-0',
)}
/>
</SwitchPrimitives.Root>
));
Switch.displayName = SwitchPrimitives.Root.displayName;

export { Switch };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React from 'react';

import { cn } from '@/utils/shadcn-ui.util';

Expand Down
11 changes: 11 additions & 0 deletions lib/platform-bible-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,14 @@ export {
VerticalTabsContent,
VerticalTabsTrigger,
} from '@/components/shadcn-ui/tabs-vertical';
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
CardContent,
} from './components/shadcn-ui/card';
export { Alert, AlertTitle, AlertDescription } from './components/shadcn-ui/alert';
export { Slider as ShadCnSlider } from './components/shadcn-ui/slider';
export { Switch as ShadCnSwitch } from './components/shadcn-ui/switch';
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@ import {
TableHeader,
TableRow,
} from '@/components/shadcn-ui/table';
import { AlertTitle } from '@mui/material';
import { AlertCircle } from 'lucide-react';
import { useState } from 'react';
import {
Alert,
AlertDescription,
Button,
Card,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
Expand All @@ -20,6 +30,8 @@ import {
DropdownMenuShortcut,
DropdownMenuTrigger,
Input,
Slider,
Switch,
Tabs,
TabsContent,
TabsList,
Expand Down Expand Up @@ -54,18 +66,36 @@ const invoices = [
];

function Basics({ direction }: HasDirection) {
const [sliderValue, setSlider] = useState(3);
return (
<div>
<p className="pr-mb-2 pr-text-muted-foreground">A place for the most simple components</p>
<VerticalTabs defaultValue="Button" dir={direction}>
<VerticalTabsList>
<VerticalTabsTrigger value="Alert">Alert</VerticalTabsTrigger>
<VerticalTabsTrigger value="Button">Button</VerticalTabsTrigger>
<VerticalTabsTrigger value="Input">Input</VerticalTabsTrigger>
<VerticalTabsTrigger value="Card">Card</VerticalTabsTrigger>
<VerticalTabsTrigger value="Dropdown Menu">Dropdown Menu</VerticalTabsTrigger>
<VerticalTabsTrigger value="Input">Input</VerticalTabsTrigger>
<VerticalTabsTrigger value="Slider">Slider</VerticalTabsTrigger>
<VerticalTabsTrigger value="Switch">Switch</VerticalTabsTrigger>
<VerticalTabsTrigger value="Tabs">Tabs</VerticalTabsTrigger>
<VerticalTabsTrigger value="Table">Table</VerticalTabsTrigger>
</VerticalTabsList>

<VerticalTabsContent value="Alert">
<Alert className="pr-max-w-64">Alert! Why do I look like a Card? 🤔</Alert>
<Alert variant="destructive" className="pr-max-w-64">
{/* not sure, why this is displaying black, in the sandbox it's red 🤷 */}
<AlertCircle />
<AlertTitle>Settings are incomplete</AlertTitle>
<AlertDescription>
Results from the Capitalization check may be misleading because settings are
incomplete
</AlertDescription>
</Alert>
</VerticalTabsContent>

<VerticalTabsContent value="Button">
<table>
<tbody>
Expand Down Expand Up @@ -98,6 +128,23 @@ function Basics({ direction }: HasDirection) {
</table>
</VerticalTabsContent>

<VerticalTabsContent value="Card">
<Card className="sm:col-span-2">
<CardHeader className="pb-3">Hello World</CardHeader>
</Card>
<Card className="sm:col-span-2">
<CardHeader className="pb-3">
<CardTitle>Psalms Layer-by-Layer</CardTitle>
<CardDescription className="max-w-lg text-balance leading-relaxed flex">
Unpacking the meaning of the Psalms for translators
</CardDescription>
</CardHeader>
<CardFooter>
<Button>More information</Button>
</CardFooter>
</Card>
</VerticalTabsContent>

<VerticalTabsContent value="Input">
<table>
<tbody>
Expand Down Expand Up @@ -148,6 +195,31 @@ function Basics({ direction }: HasDirection) {
</table>
</VerticalTabsContent>

<VerticalTabsContent value="Slider">
Default Shadcn sliders are not themed and always blue 🥺
<Slider />
<Slider isDisabled />
<Slider
min={0}
max={5}
value={sliderValue}
onChange={(_e, value) => setSlider(Array.isArray(value) ? value?.[0] : value)}
/>
{/* Wondering in which case the slider would output a number[] as its value 🤷 */}
{sliderValue}
</VerticalTabsContent>

<VerticalTabsContent value="Switch">
Default Shadcn switches are not themed and always blue 🥺
<div>
<Switch />
<Switch isDisabled />
<Switch isChecked />
<Switch isChecked isDisabled />
<Switch hasError />
</div>
</VerticalTabsContent>

<VerticalTabsContent value="Dropdown Menu">
<p>Note: the shadcn dropdown has a bad contrast to the background in dark mode</p>
<DropdownMenu>
Expand Down
Loading

0 comments on commit d584028

Please sign in to comment.