-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement universal grid refs #116
- Loading branch information
Showing
13 changed files
with
643 additions
and
101 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
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
85 changes: 85 additions & 0 deletions
85
packages/logos-docusaurus-theme/src/client/components/mdx/Grid/Grid.tsx
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,85 @@ | ||
import { THEME_BREAKPOINTS } from '@acid-info/lsd-react' | ||
import { css } from '@emotion/react' | ||
import styled from '@emotion/styled' | ||
import clsx from 'clsx' | ||
import React from 'react' | ||
import { lsdUtils } from '../../../lib/lsd.utils' | ||
import { GridItem } from './GridItem' | ||
|
||
export type GridProps = React.ComponentProps<typeof GridRoot> & {} | ||
|
||
export const Grid: { Item: typeof GridItem } & React.FC<GridProps> = ({ | ||
children, | ||
...props | ||
}) => { | ||
return ( | ||
<GridRoot {...props} className={clsx(props.className, 'hidden-scrollbar')}> | ||
{children} | ||
</GridRoot> | ||
) | ||
} | ||
|
||
Grid.Item = GridItem | ||
|
||
type GridBreakpointProps = { | ||
cols?: number | ||
wrap?: boolean | ||
gap?: string | number | ||
} | ||
|
||
const GridRoot = styled.div<{ | ||
xs?: GridBreakpointProps | ||
sm?: GridBreakpointProps | ||
md?: GridBreakpointProps | ||
lg?: GridBreakpointProps | ||
xl?: GridBreakpointProps | ||
}>` | ||
width: 100%; | ||
overflow: hidden; | ||
display: grid; | ||
gap: var(--grid-gap); | ||
grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr)); | ||
${(props) => | ||
THEME_BREAKPOINTS.map((key) => { | ||
if (!props[key]) return null | ||
const bp = props[key] as GridBreakpointProps | ||
return lsdUtils.responsive( | ||
props.theme as any, | ||
key, | ||
'up', | ||
)(css` | ||
${typeof bp.cols !== 'undefined' && | ||
` | ||
--grid-cols: ${bp.cols}; | ||
`} | ||
${typeof bp.gap !== 'undefined' && | ||
` | ||
--grid-gap: ${bp.gap}; | ||
`} | ||
${(typeof bp.wrap === 'undefined' || bp.wrap === true) && | ||
` | ||
display: grid; | ||
flex-wrap: unset; | ||
overflow-x: unset; | ||
overflow-y: unset; | ||
scroll-snap-type: unset; | ||
`} | ||
${typeof bp.wrap !== 'undefined' && | ||
bp.wrap === false && | ||
` | ||
display: flex; | ||
flex-wrap: nowrap; | ||
overflow-x: scroll; | ||
overflow-y: hidden; | ||
scroll-snap-type: x mandatory; | ||
`} | ||
`) | ||
})} | ||
` |
40 changes: 40 additions & 0 deletions
40
packages/logos-docusaurus-theme/src/client/components/mdx/Grid/GridItem.tsx
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,40 @@ | ||
import clsx from 'clsx' | ||
import React from 'react' | ||
import styled from '@emotion/styled' | ||
import { THEME_BREAKPOINTS } from '@acid-info/lsd-react' | ||
import { lsdUtils } from '../../../lib/lsd.utils' | ||
import { css } from '@emotion/react' | ||
|
||
export type GridItemProps = React.ComponentProps<typeof Root> & {} | ||
|
||
export const GridItem: React.FC<GridItemProps> = ({ children, ...props }) => { | ||
return ( | ||
<Root {...props} className={clsx(props.className)}> | ||
{children} | ||
</Root> | ||
) | ||
} | ||
|
||
const Root = styled.div<{ | ||
xs?: number | ||
sm?: number | ||
md?: number | ||
lg?: number | ||
xl?: number | ||
}>` | ||
${(props) => | ||
THEME_BREAKPOINTS.map((key) => { | ||
if (!props[key]) return null | ||
const bp = props[key] as number | ||
return lsdUtils.responsive( | ||
props.theme as any, | ||
key, | ||
'up', | ||
)(css` | ||
grid-column: span ${bp}; | ||
flex-basis: calc(100% / var(--grid-cols) * ${bp}); | ||
`) | ||
})} | ||
` |
2 changes: 2 additions & 0 deletions
2
packages/logos-docusaurus-theme/src/client/components/mdx/Grid/index.ts
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,2 @@ | ||
export * from './Grid' | ||
export * from './GridItem' |
Oops, something went wrong.