-
Notifications
You must be signed in to change notification settings - Fork 0
Add-BNDrawer #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dallasbpeters
wants to merge
4
commits into
main
Choose a base branch
from
add-BNDrawer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add-BNDrawer #48
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8a1711a
prettier
dallasbpeters 1e243ab
bump version number
dallasbpeters 1369364
Update CHANGELOG for version 1.2.0: Added BNDialogTitle and BNDrawer …
dallasbpeters be4a625
Refactor BNDialogTitle and BNDrawer components to use children prop f…
dallasbpeters File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,77 @@ | ||
| import CloseRounded from '@mui/icons-material/CloseRounded' | ||
| import { | ||
| DialogTitle, | ||
| type DialogTitleProps, | ||
| IconButton, | ||
| Stack, | ||
| Typography, | ||
| } from '@mui/material' | ||
| import type { SxProps, Theme } from '@mui/material' | ||
|
|
||
| export type BNDialogTitleBgColorVariant = 'background.paper' | 'appBarPrimary.defaultFill' | ||
|
|
||
| export type BNDialogTitleTextColorVariant = | ||
| | 'text.primary' | ||
| | 'appBarPrimary.defaultContrast' | ||
|
|
||
| export interface BNDialogTitleProps extends Omit<DialogTitleProps, 'variant'> { | ||
| bgColorVariant?: BNDialogTitleBgColorVariant | ||
| textColorVariant?: BNDialogTitleTextColorVariant | ||
| variant?: 'default' | 'primary' | ||
| onClose?: () => void | ||
| closeAriaLabel?: string | ||
| } | ||
|
|
||
| export const BNDialogTitle = ({ | ||
| bgColorVariant, | ||
| textColorVariant, | ||
| variant, | ||
| onClose, | ||
| closeAriaLabel = 'Close dialog', | ||
dallasbpeters marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| title, | ||
dallasbpeters marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sx, | ||
| ...rest | ||
| }: BNDialogTitleProps) => { | ||
| const preset = | ||
| variant === 'primary' | ||
| ? { bg: 'appBarPrimary.defaultFill', text: 'appBarPrimary.defaultContrast' } | ||
| : variant === 'default' || !variant | ||
| ? { bg: 'background.paper', text: 'text.primary' } | ||
| : undefined | ||
|
|
||
| const resolvedBg = (bgColorVariant ?? preset?.bg ?? 'background.paper') as string | ||
| const resolvedText = (textColorVariant ?? preset?.text ?? 'text.primary') as string | ||
|
|
||
| const readCssVar = (theme: Theme, path: string): string | undefined => { | ||
| return path | ||
| .split('.') | ||
| .reduce<any>((obj, key) => (obj ? obj[key] : undefined), (theme as any).vars) | ||
| } | ||
|
|
||
| const colorRule = (theme: Theme) => ({ | ||
| backgroundColor: readCssVar(theme, `palette.${resolvedBg}`), | ||
| color: readCssVar(theme, `palette.${resolvedText}`), | ||
| }) | ||
|
|
||
| const mergedSx: SxProps<Theme> = sx | ||
| ? [colorRule, ...(Array.isArray(sx) ? sx : [sx])] | ||
| : [colorRule] | ||
|
|
||
| return ( | ||
| <DialogTitle sx={mergedSx} {...rest}> | ||
| <Stack direction="row" alignItems="center" justifyContent="space-between" gap={1}> | ||
| <Typography variant="h4">{title}</Typography> | ||
dallasbpeters marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {onClose && ( | ||
| <IconButton | ||
| aria-label={closeAriaLabel} | ||
| color="inherit" | ||
| onClick={onClose} | ||
| size="large" | ||
| > | ||
| <CloseRounded fontSize="medium" /> | ||
| </IconButton> | ||
| )} | ||
| </Stack> | ||
| </DialogTitle> | ||
| ) | ||
| } | ||
This file contains hidden or 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,16 @@ | ||
| import { Drawer, type DrawerProps } from '@mui/material' | ||
|
|
||
| import { BNDialogTitle, type BNDialogTitleProps } from './BNDialogTitle' | ||
|
|
||
| export interface BNDrawerProps extends DrawerProps { | ||
| titleProps?: BNDialogTitleProps | ||
| } | ||
|
|
||
| export const BNDrawer = ({ titleProps, children, ...drawerProps }: BNDrawerProps) => { | ||
| return ( | ||
| <Drawer {...drawerProps}> | ||
| {titleProps && <BNDialogTitle {...titleProps} />} | ||
| {children} | ||
| </Drawer> | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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,83 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react-vite' | ||
| import React from 'react' | ||
|
|
||
| import { | ||
| Accordion, | ||
| AccordionDetails, | ||
| AccordionSummary, | ||
| Box, | ||
| Button, | ||
| CardActions, | ||
| Typography, | ||
| } from '@mui/material' | ||
|
|
||
| import { BNDrawer } from '../components/drawer/BNDrawer' | ||
|
|
||
| const meta = { | ||
| title: 'Custom Components/BNDrawer', | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| controls: { | ||
| exclude: ['LinkComponent'], | ||
| }, | ||
| }, | ||
| argTypes: { | ||
| color: { | ||
| control: 'select', | ||
| options: ['default', 'secondary'], | ||
| }, | ||
dallasbpeters marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| component: BNDrawer, | ||
| } satisfies Meta<typeof BNDrawer> | ||
|
|
||
| export default meta | ||
|
|
||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| export const Primary: Story = { | ||
| parameters: { | ||
| layout: 'padded', | ||
| }, | ||
| args: { | ||
| variant: 'temporary', | ||
| titleProps: { | ||
| title: 'Drawer Title', | ||
| variant: 'primary', | ||
| }, | ||
| }, | ||
| render: (args) => { | ||
| const [open, setOpen] = React.useState(false) | ||
| const toggleDrawer = (newOpen: boolean) => () => setOpen(newOpen) | ||
| return ( | ||
| <> | ||
| <Button onClick={toggleDrawer(true)}>Open drawer</Button> | ||
| <BNDrawer | ||
| {...args} | ||
| open={open} | ||
| onClose={toggleDrawer(false)} | ||
| titleProps={{ ...args.titleProps, onClose: toggleDrawer(false) }} | ||
| > | ||
| <Box | ||
| sx={{ p: 3, width: '100%', maxWidth: 500, minWidth: { xs: '100%', md: 500 } }} | ||
| > | ||
| <Typography variant="h5" gutterBottom> | ||
| Drawer Content accepts any children | ||
| </Typography> | ||
| <Accordion variant="outlined"> | ||
| <AccordionSummary> | ||
| <Typography variant="body2">Accordion 1</Typography> | ||
| </AccordionSummary> | ||
| <AccordionDetails> | ||
| <Typography variant="body2">Accordion 1 content</Typography> | ||
| </AccordionDetails> | ||
| </Accordion> | ||
| </Box> | ||
| <CardActions> | ||
| <Button variant="outlined">Action</Button> | ||
| <Button variant="contained">Action</Button> | ||
| </CardActions> | ||
| </BNDrawer> | ||
| </> | ||
| ) | ||
| }, | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.