Skip to content

Commit 7542e2b

Browse files
committed
feat: bem
Signed-off-by: Innei <[email protected]>
1 parent 0a34e1f commit 7542e2b

File tree

12 files changed

+67
-37
lines changed

12 files changed

+67
-37
lines changed

.github/workflows/build.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
with:
3939
version: 8.x.x
4040
run_install: true
41-
- run: pnpm run package
42-
- run: pnpm run test
41+
- run: pnpm run build
4342
env:
4443
CI: true

demo/app/layout.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@/styles/globals.css"
22
import { Metadata } from "next"
33
import { motion } from "framer-motion"
4-
import { ModalStackContainer } from "rc-modal-sheet"
4+
import { ModalStackContainer } from "rc-modal-sheet/src/helpers/motion"
55

66
import { siteConfig } from "@/config/site"
77
import { fontSans } from "@/lib/fonts"
@@ -47,11 +47,12 @@ export default function RootLayout({ children }: RootLayoutProps) {
4747
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
4848
<div className="relative flex min-h-screen flex-col">
4949
<SiteHeader />
50-
<div className="flex-1">{children}</div>
50+
<ModalStackContainer>
51+
<div className="flex-1">{children}</div>
52+
</ModalStackContainer>
5153
</div>
5254
<TailwindIndicator />
5355
</ThemeProvider>
54-
<Providers />
5556
</body>
5657
</html>
5758
</>

demo/app/page.tsx

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
import Link from "next/link"
1+
"use client"
22

3-
import { siteConfig } from "@/config/site"
4-
import { buttonVariants } from "@/components/ui/button"
3+
import { useModalStack } from "~/modal"
4+
5+
import { Button, buttonVariants } from "@/components/ui/button"
56

67
export default function IndexPage() {
8+
const { present } = useModalStack()
79
return (
810
<section className="container grid items-center gap-6 pb-8 pt-6 md:py-10">
911
<div className="flex max-w-[980px] flex-col items-start gap-2">
1012
<h1 className="text-3xl font-extrabold leading-tight tracking-tighter md:text-4xl">
1113
Beautifully designed components <br className="hidden sm:inline" />
1214
built with Radix UI and Tailwind CSS.
1315
</h1>
14-
<p className="max-w-[700px] text-lg text-muted-foreground">
16+
<p className="text-muted-foreground max-w-[700px] text-lg">
1517
Accessible and customizable components that you can copy and paste
1618
into your apps. Free. Open Source. And Next.js 13 Ready.
1719
</p>
1820
</div>
1921
<div className="flex gap-4">
20-
<Link
21-
href={siteConfig.links.docs}
22-
target="_blank"
23-
rel="noreferrer"
22+
<Button
23+
onClick={() => {
24+
present({
25+
title: "Modal",
26+
content: () => <div>Modal</div>,
27+
})
28+
}}
2429
className={buttonVariants()}
2530
>
26-
Documentation
27-
</Link>
28-
<Link
29-
target="_blank"
30-
rel="noreferrer"
31-
href={siteConfig.links.github}
32-
className={buttonVariants({ variant: "outline" })}
33-
>
34-
GitHub
35-
</Link>
31+
Present
32+
</Button>
3633
</div>
3734
</section>
3835
)

demo/app/provider.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"use client"
22

3+
import type { PropsWithChildren } from "react"
34
import { motion } from "framer-motion"
45
import { ModalStackContainer } from "~/modal"
56

6-
export const Providers = () => <ModalStackContainer m={motion} />
7+
export const Providers = (props: PropsWithChildren) => (
8+
<ModalStackContainer m={motion}>{props.children}</ModalStackContainer>
9+
)

demo/tailwind.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ const { fontFamily } = require("tailwindcss/defaultTheme")
33
/** @type {import('tailwindcss').Config} */
44
module.exports = {
55
darkMode: ["class"],
6-
content: ["app/**/*.{ts,tsx}", "components/**/*.{ts,tsx}"],
6+
content: [
7+
"app/**/*.{ts,tsx}",
8+
"components/**/*.{ts,tsx}",
9+
"./node_modules/rc-modal-sheet/src/**/*.{ts,tsx}",
10+
],
711
theme: {
812
container: {
913
center: true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
".": {
1717
"import": "./src/index.ts"
1818
},
19-
"./*": {
19+
"./src/*": {
2020
"import": "./src/*"
2121
}
2222
},

src/dialog/DialogOverlay.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const DialogOverlay = ({
1414
<Dialog.Overlay asChild>
1515
<m.div
1616
onClick={onClick}
17-
className="fixed inset-0 z-[11] bg-zinc-50/80 dark:bg-neutral-900/80"
17+
className="fixed inset-0 z-[11] bg-zinc-50/80 dark:bg-zinc-950/80"
1818
initial={{ opacity: 0 }}
1919
animate={{ opacity: 1 }}
2020
exit={{ opacity: 0 }}

src/helpers/m.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use client'
22

33
import { m } from 'framer-motion'
4+
import type { PropsWithChildren } from 'react'
45

56
import { ModalStackContainer as MSC } from '~/modal'
67

7-
export const ModalStackContainer = () => <MSC m={m} />
8+
export const ModalStackContainer = (props: PropsWithChildren) => (
9+
<MSC m={m}>{props.children}</MSC>
10+
)

src/helpers/motion.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use client'
22

33
import { motion } from 'framer-motion'
4+
import type { PropsWithChildren } from 'react'
45

56
import { ModalStackContainer as MSC } from '~/modal'
67

7-
export const ModalStackContainer = () => <MSC m={motion} />
8+
export const ModalStackContainer = (props: PropsWithChildren) => (
9+
<MSC m={motion}>{props.children}</MSC>
10+
)

src/modal/stacked/bem.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const root = 'rm-dialog'
2+
export const ModalBEM = {
3+
root,
4+
children: `${root}__children`,
5+
close: `${root}__close`,
6+
content: `${root}__content`,
7+
title: `${root}__title`,
8+
}

src/modal/stacked/container.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useMemo } from 'react'
44
import { AnimatePresence } from 'framer-motion'
5-
import type { FC } from 'react'
5+
import type { FC, PropsWithChildren } from 'react'
66
import type { ModalStackContainerProps } from './types'
77

88
import {
@@ -16,11 +16,14 @@ import {
1616

1717
import { Modal } from './modal'
1818

19-
export const ModalStackContainer: FC<ModalStackContainerProps> = (props) => {
20-
const { m, isMobile, ...config } = props
19+
export const ModalStackContainer: FC<
20+
ModalStackContainerProps & PropsWithChildren
21+
> = (props) => {
22+
const { m, isMobile, children } = props
2123
return (
2224
<ModalStackProvider>
2325
<SheetStackProvider>
26+
{children}
2427
<MotionComponentContext.Provider
2528
// Keep the value stable
2629
value={useMemo(() => ({ m }), [])}
@@ -46,6 +49,7 @@ const SetMobile: FC<{ m?: boolean }> = ({ m }) => {
4649
const ModalStack = () => {
4750
const stack = useModalStackInternal()
4851

52+
console.log('stack', stack)
4953
return (
5054
<AnimatePresence mode="popLayout">
5155
{stack.map((item, index) => {

src/modal/stacked/modal.tsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from '~/providers'
3232

3333
import { PresentSheet } from '../../sheet'
34+
import { ModalBEM } from './bem'
3435

3536
const microReboundPreset: Spring = {
3637
type: 'spring',
@@ -174,6 +175,7 @@ export const Modal: Component<{
174175
<Dialog.Content asChild>
175176
<div
176177
className={clsxm(
178+
ModalBEM.root,
177179
'fixed inset-0 z-[20] overflow-auto',
178180
modalContainerClassName,
179181
)}
@@ -197,6 +199,7 @@ export const Modal: Component<{
197199
<Dialog.Content asChild>
198200
<div
199201
className={clsxm(
202+
ModalBEM.root,
200203
'fixed inset-0 z-[20] flex items-center justify-center',
201204
modalContainerClassName,
202205
)}
@@ -209,9 +212,10 @@ export const Modal: Component<{
209212
animate={animateController}
210213
transition={microReboundPreset}
211214
className={clsxm(
215+
ModalBEM.content,
212216
'relative flex flex-col overflow-hidden rounded-lg',
213-
'bg-zinc-50/80 dark:bg-neutral-900/80',
214-
'p-2 shadow-2xl shadow-stone-300 backdrop-blur-sm dark:shadow-stone-800',
217+
'bg-zinc-50/80 dark:bg-zinc-950/80',
218+
'p-2 shadow-2xl shadow-gray-300 backdrop-blur-sm dark:shadow-gray-800/50',
215219
max
216220
? 'h-[90vh] w-[90vw]'
217221
: 'max-h-[70vh] min-w-[300px] max-w-[90vw] lg:max-h-[calc(100vh-20rem)] lg:max-w-[70vw]',
@@ -221,18 +225,22 @@ export const Modal: Component<{
221225
)}
222226
onClick={stopPropagation}
223227
>
224-
<Dialog.Title className="flex-shrink-0 px-4 py-2 text-lg font-medium">
228+
<Dialog.Title
229+
className={`${ModalBEM.title} flex-shrink-0 px-4 py-2 text-lg font-medium`}
230+
>
225231
{title}
226232
</Dialog.Title>
227233
<Divider className="my-2 flex-shrink-0 border-slate-200 opacity-80 dark:border-neutral-800" />
228234

229-
<div className="min-h-0 flex-shrink flex-grow overflow-auto px-4 py-2">
235+
<div
236+
className={`${ModalBEM.children} min-h-0 flex-shrink flex-grow overflow-auto px-4 py-2`}
237+
>
230238
{finalChildren}
231239
</div>
232240

233241
<Dialog.DialogClose
234242
onClick={close}
235-
className="absolute right-0 top-0 z-[9] p-5"
243+
className={`${ModalBEM.close} absolute right-0 top-0 z-[9] p-5`}
236244
>
237245
<CloseIcon />
238246
</Dialog.DialogClose>

0 commit comments

Comments
 (0)