Skip to content

Commit

Permalink
Feat/modal (#202)
Browse files Browse the repository at this point in the history
* chore: initial set up

* chore: add close

* chore: add close modal icon

* chore: style modal for docs

* chore: dark mode

* chore: replace dialog with modal

* chore: add docs

* chore: modal open bg colour

* chore: add description

* chore: remove animations

* chore: use correct shadow opacity

* chore: remove closemodal icon

* chore: remove close modal icon

* fix: text-foreground-muted

* chore: add component attributes

* chore: update docs
  • Loading branch information
yuna-iwata committed Dec 6, 2023
1 parent 422bb26 commit 4a7cb7c
Show file tree
Hide file tree
Showing 11 changed files with 666 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .storybook/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { create } from '@storybook/theming/create';
import { create } from '@storybook/theming/create'

export default create({
base: 'light',
brandTitle: 'NearForm Quantum'
});
})
77 changes: 64 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
},
"dependencies": {
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-radio-group": "^1.1.3",
"@radix-ui/react-scroll-area": "^1.0.5",
Expand Down
1 change: 0 additions & 1 deletion src/assets/build/close.icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const CloseIcon = (props: any) => (
<path
fill="inherit"
stroke="inherit"
strokeWidth={0.6}
d="m6.494 6.288-.212.212.212.212 2.64 2.64a.2.2 0 0 1-.005.277l.213.213-.213-.213a.2.2 0 0 1-.277.004l-2.64-2.64L6 6.782l-.212.213-2.642 2.641-.004.004a.199.199 0 0 1-.064.045l.118.275-.118-.275a.2.2 0 0 1-.217-.326l.004-.004 2.641-2.642.212-.212-.212-.212-2.64-2.64a.2.2 0 0 1 .282-.281l2.64 2.64.212.212.212-.213 2.642-2.641.004-.004a.199.199 0 0 1 .326.217l.275.118-.275-.118a.199.199 0 0 1-.045.064l-.004.004-2.641 2.642Z"
/>
</svg>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
) => {
const leftSideComponent =
leftSideChild ?? convertTypeToComponent.left[`${type}`]
const rightSideComponent = rightSideChild ?? <CloseIcon />
const rightSideComponent = rightSideChild ?? <CloseIcon strokeWidth={0.6} />

return (
<form className={cn(formVariants({ variant }), formClassName)}>
Expand Down
135 changes: 135 additions & 0 deletions src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
'use client'

import * as React from 'react'
import * as DialogPrimitive from '@radix-ui/react-dialog'
import { CloseIcon } from '@/assets'

import { cn } from '@/lib/utils'

const Modal = DialogPrimitive.Root

const ModalTrigger = DialogPrimitive.Trigger

const ModalPortal = DialogPrimitive.Portal

const ModalCloseFooter = DialogPrimitive.Close

const ModalOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn('fixed inset-0 z-50 bg-background/80', className)}
{...props}
/>
))
ModalOverlay.displayName = DialogPrimitive.Overlay.displayName

const ModalContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<ModalPortal>
<ModalOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 shadow-lg bg-background dark:bg-foreground duration-200 sm:rounded-lg',
className
)}
{...props}
>
{children}
</DialogPrimitive.Content>
</ModalPortal>
))
ModalContent.displayName = DialogPrimitive.Content.displayName

const ModalHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex items-center justify-between p-6 space-y-1.5 text-center sm:text-left',
className
)}
{...props}
/>
)
ModalHeader.displayName = 'ModalHeader'

const ModalFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col-reverse p-6 sm:flex-row sm:justify-start sm:space-x-2',
className
)}
{...props}
/>
)
ModalFooter.displayName = 'ModalFooter'

const ModalTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
'text-lg font-semibold leading-none tracking-tight text-foreground dark:text-foreground-inverse',
className
)}
{...props}
/>
))
ModalTitle.displayName = DialogPrimitive.Title.displayName

const ModalClose = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Close>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Close>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Close
ref={ref}
className={cn(
'rounded-sm opacity-70 ring-offset-background transition-opacity disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-foreground-muted',
className
)}
{...props}
>
<div className="text-foreground dark:text-foreground-inverse">
<CloseIcon className="w-5 h-5" strokeWidth={0.833} />
</div>
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
))

const ModalDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn('text-sm px-6 text-foreground-muted', className)}
{...props}
/>
))
ModalDescription.displayName = DialogPrimitive.Description.displayName

export {
Modal,
ModalPortal,
ModalOverlay,
ModalClose,
ModalCloseFooter,
ModalTrigger,
ModalContent,
ModalHeader,
ModalFooter,
ModalTitle,
ModalDescription
}
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './Tooltip'
export * from './Input'
export * from './Switch'
export * from './Chip'
export * from './Modal'
export * from './WebsiteFooter'
export * from './Select'
export * from './Calendar'
Loading

0 comments on commit 4a7cb7c

Please sign in to comment.