Skip to content

Commit 2855796

Browse files
authored
Merge pull request #753 from maiieul/use-styled-compoennts-in-docs
Refactor styled Modal to tailwindcss-animate
2 parents 709f3d0 + f219de4 commit 2855796

File tree

18 files changed

+398
-500
lines changed

18 files changed

+398
-500
lines changed

.changeset/slimy-snakes-poke.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
'@qwik-ui/styled': minor
3+
---
4+
5+
## tailwind.config.cjs
6+
7+
Now uses tailwindcss-animate
8+
9+
```ts
10+
plugins: [
11+
require('tailwindcss-animate'),
12+
...
13+
],
14+
```
15+
16+
Instead of manually defined animations through a custom plugin like
17+
18+
```ts
19+
plugins: [
20+
plugin(function ({ addUtilities }) {
21+
addUtilities({
22+
'.appear': {
23+
opacity: 1,
24+
},
25+
'.disappear': {
26+
opacity: 0,
27+
},
28+
});
29+
}),
30+
];
31+
```
32+
33+
## Modal refactor
34+
35+
### Modal.Panel
36+
37+
The Panel now uses tailwindcss-animate and comes built-in with 5 `position` variant props
38+
39+
```tsx
40+
export const panelVariants = cva(
41+
[
42+
'fixed w-full bg-background p-6 text-foreground transition-all backdrop:brightness-50 backdrop:backdrop-blur-sm',
43+
'data-[closing]:duration-300 data-[open]:duration-300 data-[open]:animate-in data-[closing]:animate-out',
44+
'backdrop:data-[closing]:duration-300 backdrop:data-[open]:duration-300 backdrop:data-[open]:animate-in backdrop:data-[closing]:animate-out backdrop:data-[closing]:fade-out backdrop:data-[open]:fade-in',
45+
],
46+
{
47+
variants: {
48+
position: {
49+
center:
50+
'max-w-lg rounded-base shadow-lg data-[state=closed]:fade-out data-[state=open]:fade-in data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=open]:slide-in-from-bottom-2 backdrop:data-[closing]:fade-out backdrop:data-[open]:fade-in',
51+
top: 'inset-x-0 top-0 mt-0 rounded-b-base border-b data-[closing]:slide-out-to-top data-[open]:slide-in-from-top',
52+
bottom:
53+
'inset-x-0 bottom-0 mb-0 rounded-t-base border-t data-[closing]:slide-out-to-bottom data-[open]:slide-in-from-bottom',
54+
left: 'inset-y-0 left-0 ml-0 h-full max-w-sm rounded-r-base border-r data-[closing]:slide-out-to-left data-[open]:slide-in-from-left',
55+
right:
56+
'inset-y-0 right-0 mr-0 h-full max-w-sm rounded-l-base border-l data-[closing]:slide-out-to-right data-[open]:slide-in-from-right',
57+
},
58+
},
59+
defaultVariants: {
60+
position: 'center',
61+
},
62+
},
63+
);
64+
65+
type PanelProps = PropsOf<typeof HeadlessModal.Panel> &
66+
VariantProps<typeof panelVariants>;
67+
68+
const Panel = component$<PanelProps>(({ position, ...props }) => {
69+
return (
70+
<HeadlessModal.Panel {...props} class={cn(panelVariants({ position }), props.class)}>
71+
<Slot />
72+
</HeadlessModal.Panel>
73+
);
74+
});
75+
```
76+
77+
over previous tailwind.config.js home-made plugin
78+
79+
```tsx
80+
'.appear': {
81+
opacity: 1,
82+
},
83+
'.disappear': {
84+
opacity: 0,
85+
},
86+
```
87+
88+
to avoid re-inventing the wheel.
89+
90+
### Modal.Title
91+
92+
Title now holds `text-lg font-semibold` classes.
93+
94+
### Modal.Description
95+
96+
Description now holds `text-muted-foreground` class.

.changeset/ten-actors-explain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik-ui/styled': patch
3+
---
4+
5+
Styled button now uses `transition-all` for every variant shared class

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"printWidth": 90,
66
"plugins": ["prettier-plugin-tailwindcss"],
77
"tailwindConfig": "./apps/website/tailwind.config.cjs",
8-
"tailwindFunctions": ["clsx", "cva", "cn"]
8+
"tailwindFunctions": ["clsx", "cva"]
99
}

apps/component-tests/tailwind.config.cjs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@ module.exports = {
1010
join(__dirname, '../../packages/kit-styled/src/**/*.{js,ts,jsx,tsx,mdx}'),
1111
],
1212
plugins: [
13-
require('tailwindcss-animate'),
1413
// PLUGIN-START
14+
require('tailwindcss-animate'),
1515
plugin(function ({ addUtilities }) {
1616
addUtilities({
1717
'.press': {
1818
transform: 'var(--transform-press)',
1919
},
20-
'.appear': {
21-
opacity: 1,
22-
},
23-
'.disappear': {
24-
opacity: 0,
25-
},
2620
});
2721
}),
2822
// PLUGIN-END
@@ -112,16 +106,6 @@ module.exports = {
112106
step: 'cubic-bezier(0.6, 0.6, 0, 1)',
113107
jumpy: 'cubic-bezier(0.87, 0, 0.13, 1)',
114108
},
115-
keyframes: {
116-
fadeIn: {
117-
'0%': { opacity: 0 },
118-
'100%': { opacity: 1 },
119-
},
120-
fadeOut: {
121-
'0%': { opacity: 1 },
122-
'100%': { opacity: 0 },
123-
},
124-
},
125109
},
126110
},
127111
};

apps/website/src/components/make-it-yours/make-it-yours.tsx

Lines changed: 14 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
import {
2-
$,
3-
PropsOf,
4-
component$,
5-
useComputed$,
6-
useSignal,
7-
useStyles$,
8-
} from '@builder.io/qwik';
9-
import { Modal } from '@qwik-ui/headless';
10-
import { Button } from '~/components/ui';
1+
import { $, PropsOf, component$, useComputed$ } from '@builder.io/qwik';
2+
import { Modal, Button, buttonVariants } from '~/components/ui';
113
import {
124
ThemeBaseColor,
135
ThemeBorderRadius,
@@ -25,69 +17,6 @@ import CopyCssConfig from '../copy-css-config/copy-css-config';
2517
import { useAppState } from '~/_state/use-app-state';
2618

2719
export default component$<PropsOf<typeof Button>>(() => {
28-
useStyles$(`
29-
.make-it-yours::backdrop {
30-
background: rgba(0,0,0,0.05);
31-
}
32-
33-
.make-it-yours {
34-
animation: sheetOpen 0.75s forwards cubic-bezier(0.6, 0.6, 0, 1);
35-
}
36-
37-
.make-it-yours::backdrop {
38-
animation: sheetFadeIn 0.75s forwards cubic-bezier(0.6, 0.6, 0, 1);
39-
}
40-
41-
.make-it-yours.modal-closing {
42-
animation: sheetClose 0.35s forwards cubic-bezier(0.6, 0.6, 0, 1);
43-
}
44-
45-
.make-it-yours.modal-closing::backdrop {
46-
animation: sheetFadeOut 0.35s forwards cubic-bezier(0.6, 0.6, 0, 1);
47-
}
48-
49-
@keyframes sheetOpen {
50-
from {
51-
opacity: 0;
52-
transform: translateX(100%);
53-
}
54-
to {
55-
opacity: 1;
56-
transform: translateX(0%);
57-
}
58-
}
59-
60-
@keyframes sheetClose {
61-
from {
62-
opacity: 1;
63-
transform: translateX(0%);
64-
}
65-
to {
66-
opacity: 0;
67-
transform: translateX(100%);
68-
}
69-
}
70-
71-
@keyframes sheetFadeIn {
72-
from {
73-
opacity: 0;
74-
}
75-
to {
76-
opacity: 1;
77-
}
78-
}
79-
80-
@keyframes sheetFadeOut {
81-
from {
82-
opacity: 1;
83-
}
84-
to {
85-
opacity: 0;
86-
}
87-
}
88-
`);
89-
90-
const showSig = useSignal(false);
9120
const rootStore = useAppState();
9221

9322
const { theme, setTheme } = useTheme();
@@ -132,19 +61,17 @@ export default component$<PropsOf<typeof Button>>(() => {
13261
return [font, mode, style, baseColor, primaryColor, borderRadius].join(' ');
13362
});
13463
return (
135-
<Modal.Root closeOnBackdropClick={false} bind:show={showSig}>
136-
<Button
137-
size="sm"
138-
look="outline"
139-
class="flex sm:mr-2 sm:h-10"
140-
onClick$={() => {
141-
showSig.value = true;
142-
}}
64+
<Modal.Root>
65+
<Modal.Trigger
66+
class={cn(
67+
buttonVariants({ size: 'sm', look: 'outline' }),
68+
'flex sm:mr-2 sm:h-10',
69+
)}
14370
>
14471
<LuSlidersHorizontal class={cn('h-4 w-4 sm:mr-2')} />
14572
<span class={cn('hidden', 'sm:block')}>Make it yours</span>
146-
</Button>
147-
<Modal.Panel class="make-it-yours fixed bottom-[50%] right-0 top-[50%] mr-0 h-screen max-w-sm rounded-l-base border-y border-l bg-background px-4 py-8 text-foreground shadow-md sm:w-full">
73+
</Modal.Trigger>
74+
<Modal.Panel position="right">
14875
<header class="flex w-full">
14976
<h2 class="justify-self-start text-lg font-bold">Edit Profile</h2>
15077
</header>
@@ -550,9 +477,11 @@ export default component$<PropsOf<typeof Button>>(() => {
550477
</Button>
551478
<CopyCssConfig />
552479
</footer>
553-
<button onClick$={() => (showSig.value = false)} class="absolute right-4 top-5">
480+
<Modal.Close
481+
class={cn(buttonVariants({ size: 'sm', look: 'link' }), 'fixed right-4 top-5')}
482+
>
554483
<LuX class="h-8 w-8" />
555-
</button>
484+
</Modal.Close>
556485
</Modal.Panel>
557486
</Modal.Root>
558487
);

apps/website/src/routes/docs/headless/install/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import qwikdevAstroCLI from '../../../../../public/images/qwikdev-astro-cli.webp
1010
import { ConfettiButton } from './confetti-button';
1111

1212
export const packages = {
13-
npm: 'npm install @qwik-ui/headless',
14-
yarn: 'yarn add @qwik-ui/headless',
15-
pnpm: 'pnpm add @qwik-ui/headless',
13+
npm: 'npm i -D @qwik-ui/headless',
14+
yarn: 'yarn add -D @qwik-ui/headless',
15+
pnpm: 'pnpm i -D @qwik-ui/headless',
1616
};
1717

1818
export const qwikCityPackages = {

0 commit comments

Comments
 (0)