Skip to content

Commit d80258a

Browse files
committed
feat(website): add Spoiler ui component
1 parent 790ab7b commit d80258a

File tree

17 files changed

+398
-0
lines changed

17 files changed

+398
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as Spoiler from './spoiler';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type { SpoilerContentProps } from './spoiler-content.types';
2+
export { SpoilerContent } from './spoiler-content';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { SpoilerContentProps } from './spoiler-content.types';
2+
import { component$, Slot } from '@builder.io/qwik';
3+
import { Spoiler } from 'qwik-primitives';
4+
5+
/**
6+
* The component that contains the spoiler content.
7+
* Must be rendered inside `Spoiler.Panel`.
8+
* This component is based on the `div` element.
9+
*/
10+
export const SpoilerContent = component$<SpoilerContentProps>((props) => {
11+
return (
12+
<Spoiler.Content {...props}>
13+
<Slot />
14+
</Spoiler.Content>
15+
);
16+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { PropsOf, FunctionComponent, CSSProperties } from '@builder.io/qwik';
2+
3+
export interface SpoilerContentProps extends PropsOf<'div'> {
4+
/**
5+
* Change the default rendered element for the one passed as, merging their props and behavior.
6+
*
7+
* Read our [Composition](https://github.com/ZAHON/qwik-primitives/blob/main/packages/primitives/docs/composition.md) guide for more details.
8+
*/
9+
as?: FunctionComponent;
10+
11+
/**
12+
* The CSS class for the element.
13+
*/
14+
class?: string;
15+
16+
/**
17+
* The inline style for the element.
18+
*/
19+
style?: CSSProperties;
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type { SpoilerPanelProps } from './spoiler-panel.types';
2+
export { SpoilerPanel } from './spoiler-panel';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { cva } from 'class-variance-authority';
2+
3+
export const spoilerPanelStyles = cva([
4+
'motion-safe:data-[state=open]:animate-spoiler-panel-down',
5+
'motion-safe:data-[state=closed]:animate-spoiler-panel-up',
6+
]);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { SpoilerPanelProps } from './spoiler-panel.types';
2+
import { component$, Slot } from '@builder.io/qwik';
3+
import { Spoiler } from 'qwik-primitives';
4+
import { twm } from '@/utilities/twm';
5+
import { spoilerPanelStyles } from './spoiler-panel.styles';
6+
7+
/**
8+
* The panel that expands/collapses.
9+
* This component is based on the `div` element.
10+
*/
11+
export const SpoilerPanel = component$<SpoilerPanelProps>((props) => {
12+
const { class: className, ...others } = props;
13+
14+
return (
15+
<Spoiler.Panel class={twm(spoilerPanelStyles(), className)} {...others}>
16+
<Slot />
17+
</Spoiler.Panel>
18+
);
19+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { PropsOf, FunctionComponent, QRL, CSSProperties } from '@builder.io/qwik';
2+
3+
export interface SpoilerPanelProps extends PropsOf<'div'> {
4+
/**
5+
* Change the default rendered element for the one passed as, merging their props and behavior.
6+
*
7+
* Read our [Composition](https://github.com/ZAHON/qwik-primitives/blob/main/packages/primitives/docs/composition.md) guide for more details.
8+
*/
9+
as?: FunctionComponent;
10+
11+
/**
12+
* The minimum height of the panel when spolier is closed.
13+
* @default "0px"
14+
*/
15+
minHeight?: string;
16+
17+
/**
18+
* Event handler called when the panel is fully open.
19+
* If you animate the size of the panel when it opens this event handler was call after animation end.
20+
*/
21+
onOpen$?: QRL<() => void>;
22+
23+
/**
24+
* Event handler called when the panel is fully close.
25+
* If you animate the size of the panel when it closes this event handler was call after animation end.
26+
*/
27+
onClose$?: QRL<() => void>;
28+
29+
/**
30+
* The CSS class for the element.
31+
*/
32+
class?: string;
33+
34+
/**
35+
* The inline style for the element.
36+
*/
37+
style?: CSSProperties;
38+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type { SpoilerRootProps } from './spoiler-root.types';
2+
export { SpoilerRoot } from './spoiler-root';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { SpoilerRootProps } from './spoiler-root.types';
2+
import { component$, Slot } from '@builder.io/qwik';
3+
import { Spoiler } from 'qwik-primitives';
4+
5+
/**
6+
* Contains all the parts of a spoiler.
7+
* This component is based on the `div` element.
8+
*/
9+
export const SpoilerRoot = component$<SpoilerRootProps>((props) => {
10+
return (
11+
<Spoiler.Root {...props}>
12+
<Slot />
13+
</Spoiler.Root>
14+
);
15+
});

0 commit comments

Comments
 (0)