-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from IK-Akmal/feature/modal
Feature/modal
- Loading branch information
Showing
48 changed files
with
291 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-6.78 KB
(49%)
.loki/reference/chrome_iphone7_Page_NotFoundPage_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-909 Bytes
(95%)
.loki/reference/chrome_iphone7_Widgets_Sidebar_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { Decorator } from '@storybook/react'; | ||
import { useEffect } from 'react'; | ||
|
||
export const ThemeDecorator:Decorator = (Story, context) => { | ||
const { globals: { scheme } } = context; | ||
return ( | ||
<div className={`app ${scheme}`}> | ||
<Story /> | ||
</div> | ||
); | ||
export const ThemeDecorator: Decorator = (Story, context) => { | ||
const { | ||
globals: { scheme }, | ||
} = context; | ||
|
||
useEffect(() => { | ||
document.documentElement.setAttribute('theme', scheme); | ||
}, [scheme]); | ||
|
||
return <Story />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
import { classNames } from 'shared/lib/classNames'; | ||
|
||
import { AppRouter } from './providers/router'; | ||
import { useTheme } from './providers/ThemeProvider'; | ||
|
||
import './styles/index.scss'; | ||
|
||
const App = () => { | ||
const { theme } = useTheme(); | ||
|
||
return ( | ||
<div className={classNames('app', theme)}> | ||
<AppRouter /> | ||
</div> | ||
); | ||
}; | ||
const App = () => ( | ||
<div className="app"> | ||
<AppRouter /> | ||
</div> | ||
); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
@import "reset"; | ||
@import "variables/global"; | ||
@import "themes/normal"; | ||
@import "themes/dark"; | ||
@import 'reset'; | ||
@import 'variables/global'; | ||
@import 'themes/normal'; | ||
@import 'themes/dark'; | ||
|
||
.app { | ||
body { | ||
font: var(--font-m); | ||
background: var(--bg-color); | ||
color: var(--primary-color); | ||
} | ||
|
||
.app { | ||
min-height: 100vh; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
.app.dark { | ||
:root[theme='dark'] { | ||
--bg-color: #090949; | ||
--inverted-bg-color: #e8e8ea; | ||
--primary-color:#04ff04; | ||
--primary-color: #04ff04; | ||
--secondary-color: #049604; | ||
--inverted-primary-color:#0452ff; | ||
--inverted-primary-color: #0452ff; | ||
--inverted-secondary-color: #0232c2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.modal { | ||
position: fixed; | ||
inset: 0; | ||
z-index: var(--modal-z-index); | ||
visibility: hidden; | ||
opacity: 0; | ||
pointer-events: none; | ||
|
||
.overlay { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
height: 100%; | ||
background: var(--overlay-color); | ||
} | ||
|
||
.content { | ||
padding: 20px; | ||
border-radius: 12px; | ||
background: var(--bg-color); | ||
transition: 0.3s transform; | ||
transform: scale(0.5); | ||
max-width: 60%; | ||
} | ||
} | ||
|
||
.opened { | ||
visibility: visible; | ||
opacity: 1; | ||
pointer-events: all; | ||
|
||
.content { | ||
transform: scale(1); | ||
} | ||
} | ||
|
||
.isClosing { | ||
.content { | ||
transform: scale(0.2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DetailedHTMLProps, HTMLAttributes } from 'react'; | ||
|
||
interface ModalProps extends DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>{ | ||
isOpen?:boolean; | ||
onClose?: VoidFunction; | ||
} | ||
|
||
export default ModalProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useState } from 'react'; | ||
|
||
import { Button, ButtonTheme } from '../Button'; | ||
|
||
import Modal from './Modal'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
type ModalType = typeof Modal; | ||
type Story = StoryObj<ModalType>; | ||
|
||
const meta: Meta<ModalType> = { | ||
title: 'Shared/Modal', | ||
component: Modal, | ||
}; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: 'Description', | ||
}, | ||
render: function Render(args) { | ||
const [visible, setVisible] = useState(false); | ||
|
||
const onChange = () => { | ||
setVisible((prev) => !prev); | ||
}; | ||
|
||
const buttonContent = 'Open modal'; | ||
|
||
return ( | ||
<> | ||
<Button theme={ButtonTheme.Background} onClick={onChange}> | ||
{buttonContent} | ||
</Button> | ||
{/* eslint-disable-next-line react/jsx-props-no-spreading */} | ||
<Modal {...args} isOpen={visible} onClose={onChange} /> | ||
</> | ||
); | ||
}, | ||
}; | ||
|
||
export default meta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
MouseEvent, useCallback, useEffect, useRef, useState, | ||
} from 'react'; | ||
import { classNames } from 'shared/lib/classNames'; | ||
|
||
import { Portal } from '../Portal'; | ||
|
||
import ModalProps from './Modal.props'; | ||
import styles from './Modal.module.scss'; | ||
|
||
const ANIMATION_DELAY = 200; | ||
|
||
const Modal = ({ | ||
isOpen, onClose, className, children, ...other | ||
}: ModalProps) => { | ||
const [isClosing, setIsClosing] = useState<boolean>(false); | ||
|
||
const timerRef = useRef<number>(); | ||
|
||
const closeHandler = useCallback(() => { | ||
if (onClose) { | ||
setIsClosing(true); | ||
timerRef.current = window.setTimeout(() => { | ||
onClose(); | ||
setIsClosing(false); | ||
}, ANIMATION_DELAY); | ||
} | ||
}, [onClose]); | ||
|
||
const onKeyDown = useCallback( | ||
(event: KeyboardEvent) => { | ||
if (event.key === 'Escape') { | ||
closeHandler(); | ||
} | ||
}, | ||
[closeHandler], | ||
); | ||
|
||
const contentHandler = (event: MouseEvent<HTMLDivElement>) => { | ||
event.stopPropagation(); | ||
}; | ||
|
||
useEffect(() => { | ||
if (isOpen) { | ||
window.addEventListener('keydown', onKeyDown); | ||
} | ||
|
||
return () => { | ||
window.removeEventListener('keydown', onKeyDown); | ||
}; | ||
}, [onKeyDown, isOpen]); | ||
|
||
useEffect(() => () => window.clearTimeout(timerRef.current), []); | ||
|
||
return ( | ||
<Portal> | ||
<section | ||
className={classNames(styles.modal, className, { | ||
[styles.opened]: isOpen, | ||
[styles.isClosing]: isClosing, | ||
})} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...other} | ||
> | ||
<div className={styles.overlay} onClick={closeHandler} aria-hidden="true"> | ||
<div className={styles.content} onClick={contentHandler} aria-hidden="true"> | ||
{children} | ||
</div> | ||
</div> | ||
</section> | ||
</Portal> | ||
); | ||
}; | ||
|
||
export default Modal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export interface PortalProps { | ||
children: ReactNode; | ||
element?: HTMLElement; | ||
} |
Oops, something went wrong.