Skip to content

Commit

Permalink
Add the Placeholder component
Browse files Browse the repository at this point in the history
  • Loading branch information
Studio384 committed Jul 20, 2022
1 parent 3b2be81 commit d43ac0b
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 6 deletions.
28 changes: 28 additions & 0 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ interface IButtonProps<T> extends ButtonHTMLAttributes<HTMLButtonElement> {
* As what the component should be rendered
*/
as?: T;
/**
* Is the button a placeholder
*/
placeholderWidth?: 0 | 1 | 2 | 3 | 4 | 5 | 25 | 50 | 75 | 100 | 'auto';
/**
* Button contents.
*/
Expand All @@ -65,10 +69,34 @@ export function Button<T extends ElementType>({
href,
className,
as,
placeholderWidth,
...props
}: ButtonProps<T>) {
const Component = useMemo(() => (as ? as : (href ? 'a' : 'button')) as ElementType, [as, href]);

if (placeholderWidth) {
return (
<button
type="button"
className={clsx(
'btn',
'placeholder',
'disabled',
`w-${placeholderWidth}`,
`btn-${variant}`,
{
[`btn-${size}`]: size !== 'md',
[`${color}`]: variant === 'color' || variant === 'hover',
'btn-block': block,
},
className
)}
disabled
{...props}
/>
);
}

return (
<Component
type="button"
Expand Down
37 changes: 37 additions & 0 deletions src/components/Placeholder/Placeholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { ReactNode } from 'react';

import { Dialog } from '@headlessui/react';

import clsx from 'clsx';

export interface PlaceholderProps {
/**
* Custom classes for the placeholder
*/
className?: string;
/**
* The width of the placeholder
*/
width?: 0 | 1 | 2 | 3 | 4 | 5 | 25 | 50 | 75 | 100 | 'auto';
}

/**
* Primary UI component for user interaction
*/
export const Placeholder = ({
width,
className
}: PlaceholderProps) => {
return (
<span
className={clsx(
'placeholder',
'me-1',
`w-${width}`,
className
)}
/>
);
};

export default Placeholder;
2 changes: 2 additions & 0 deletions src/components/Placeholder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './Placeholder';
export type { PlaceholderProps } from './Placeholder';
3 changes: 3 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ export type { PivotPanelProps } from '@components/PivotPanel';
export { default as PivotPanels } from '@components/PivotPanels';
export type { PivotPanelsProps } from '@components/PivotPanels';

export { default as Placeholder } from '@components/Placeholder';
export type { PlaceholderProps } from '@components/Placeholder';

export { default as Progress } from '@components/Progress';
export type { ProgressProps } from '@components/Progress';

Expand Down
2 changes: 2 additions & 0 deletions src/docs/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import MenuDemo from './pages/Components/MenuDemo';
import NavDemo from './pages/Components/NavDemo';
import OffcanvasDemo from './pages/Components/OffcanvasDemo';
import PivotDemo from './pages/Components/PivotDemo';
import PlaceholderDemo from './pages/Components/PlaceholderDemo';
import ProgressDemo from './pages/Components/ProgressDemo';
import RadioDemo from './pages/Forms/RadioDemo';
import RangeDemo from './pages/Forms/RangeDemo';
Expand Down Expand Up @@ -61,6 +62,7 @@ function App() {
<Route path="/nav" element={<NavDemo />} />
<Route path="/offcanvas" element={<OffcanvasDemo />} />
<Route path="/pivot" element={<PivotDemo />} />
<Route path="/placeholder" element={<PlaceholderDemo />} />
<Route path="/progress" element={<ProgressDemo />} />
<Route path="/radio" element={<RadioDemo />} />
<Route path="/range" element={<RangeDemo />} />
Expand Down
1 change: 1 addition & 0 deletions src/docs/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function Layout({ children }) {
<ListItem primary="Nav" onClick={() => navigate('/nav')} />
<ListItem primary="Offcanvas" onClick={() => navigate('/offcanvas')} />
<ListItem primary="Pivot" onClick={() => navigate('/pivot')} />
<ListItem primary="Placeholder" onClick={() => navigate('/placeholder')} />
<ListItem primary="Progress" onClick={() => navigate('/progress')} />
<ListItem primary="Toolbar" onClick={() => navigate('/toolbar')} />
</List>
Expand Down
2 changes: 1 addition & 1 deletion src/docs/pages/Components/DialogDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
DialogHeader,
} from "@components";

export default function GridDemo() {
export default function DialogDemo() {
const [open, setOpen] = useState(false);

return (
Expand Down
6 changes: 1 addition & 5 deletions src/docs/pages/Components/DropdownDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useState } from "react";

import DemoBox from "@docs/components/DemoBox";

import {
Expand All @@ -8,9 +6,7 @@ import {
DropdownItem
} from "@components";

export default function GridDemo() {
const [open, setOpen] = useState(false);

export default function DropdownDemo() {
return (
<>
<h2>Dialog</h2>
Expand Down
52 changes: 52 additions & 0 deletions src/docs/pages/Components/PlaceholderDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useState } from "react";

import DemoBox from "@docs/components/DemoBox";

import {
Button,
Card,
CardBody,
CardTitle,
Grid,
Placeholder,
} from "@components";

export default function PlaceholderDemo() {
const [open, setOpen] = useState(false);

return (
<>
<h2>Placeholder</h2>
<DemoBox>
<Grid>
<Card className="me-2" aria-hidden="true" style={{ width: 240 }}>
<CardBody>
<CardTitle>
Hello card
</CardTitle>
<p>
What an <span className="text-accent">beautiful</span> day for a fully loaded card of content, isn't it?
</p>
<Button href="#" variant="primary">Get started</Button>
</CardBody>
</Card>
<Card className="me-2" aria-hidden="true" style={{ width: 240 }}>
<CardBody>
<CardTitle>
<Placeholder width={5} />
</CardTitle>
<p>
<Placeholder width={3} />
<span className="text-accent"><Placeholder width={4} /></span>
<Placeholder width={4} />
<Placeholder width={5} />
<Placeholder width={2} />
</p>
<Button href="#" variant="primary" placeholderWidth={5}>Get started</Button>
</CardBody>
</Card>
</Grid>
</DemoBox>
</>
);
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ export type { PivotPanelProps } from '@components/PivotPanel';
export { default as PivotPanels } from '@components/PivotPanels';
export type { PivotPanelsProps } from '@components/PivotPanels';

export { default as Placeholder } from '@components/Placeholder';
export type { PlaceholderProps } from '@components/Placeholder';

export { default as Progress } from '@components/Progress';
export type { ProgressProps } from '@components/Progress';

Expand Down

0 comments on commit d43ac0b

Please sign in to comment.