-
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 #13 from etchteam/feature/etch-351-make-grid-into-…
…a-non-component-component-like-wrap Feature/etch 351 make grid into a non component component like wrap
- Loading branch information
Showing
5 changed files
with
359 additions
and
166 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
diamond-grid { | ||
--diamond-grid-gap: var(--diamond-spacing); | ||
display: flex; | ||
margin: calc(var(--diamond-grid-gap) * -0.5); | ||
|
||
&[inline] { | ||
display: inline-flex; | ||
} | ||
|
||
/* wrap */ | ||
|
||
&[wrap='wrap'] { | ||
flex-wrap: wrap; | ||
} | ||
|
||
&[wrap='wrap-reverse'] { | ||
flex-wrap: wrap-reverse; | ||
} | ||
|
||
&[direction='row'] { | ||
flex-direction: row; | ||
} | ||
|
||
/* direction */ | ||
|
||
&[direction='row-reverse'] { | ||
flex-direction: row-reverse; | ||
} | ||
|
||
&[direction='column'] { | ||
flex-direction: column; | ||
} | ||
|
||
&[direction='column-reverse'] { | ||
flex-direction: column-reverse; | ||
} | ||
|
||
/* justify-content */ | ||
|
||
&[justify-content='flex-start'] { | ||
justify-content: flex-start; | ||
} | ||
|
||
&[justify-content='flex-end'] { | ||
justify-content: flex-end; | ||
} | ||
|
||
&[justify-content='center'] { | ||
justify-content: center; | ||
} | ||
|
||
&[justify-content='space-between'] { | ||
justify-content: space-between; | ||
} | ||
|
||
&[justify-content='space-around'] { | ||
justify-content: space-around; | ||
} | ||
|
||
&[justify-content='space-evenly'] { | ||
justify-content: space-evenly; | ||
} | ||
|
||
/* align-items */ | ||
|
||
&[align-items='flex-start'] { | ||
align-items: flex-start; | ||
} | ||
|
||
&[align-items='flex-end'] { | ||
align-items: flex-end; | ||
} | ||
|
||
&[align-items='center'] { | ||
align-items: center; | ||
} | ||
|
||
/* gap */ | ||
|
||
&[gap='none'] { | ||
--diamond-grid-gap: 0; | ||
} | ||
|
||
&[gap='sm'] { | ||
--diamond-grid-gap: var(--diamond-spacing-sm); | ||
} | ||
|
||
&[gap='md'] { | ||
--diamond-grid-gap: var(--diamond-spacing); | ||
} | ||
|
||
&[gap='lg'] { | ||
--diamond-grid-gap: var(--diamond-spacing-lg); | ||
} | ||
|
||
&[gap='xl'] { | ||
--diamond-grid-gap: var(--diamond-spacing-xl); | ||
} | ||
} |
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,91 +1,20 @@ | ||
import { LitElement, css, html } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
|
||
import { cssMap } from '../../../lib/css-map'; | ||
|
||
const directions = ['column', 'row-reverse', 'column-reverse']; | ||
|
||
const justifys = [ | ||
'flex-end', | ||
'center', | ||
'space-between', | ||
'space-around', | ||
'space-evenly', | ||
]; | ||
|
||
const aligns = ['flex-end', 'center']; | ||
|
||
const gaps = ['xs', 'sm', 'lg', 'xl']; | ||
|
||
@customElement('diamond-grid') | ||
export class Grid extends LitElement { | ||
@property() readonly wrap?: 'wrap' | 'nowrap' | 'wrap-reverse'; | ||
@property({ type: Boolean }) readonly inline?: boolean; | ||
@property() readonly direction?: | ||
| 'row' | ||
| 'column' | ||
| 'row-reverse' | ||
| 'column-reverse' = 'row'; | ||
@property() readonly justifyContent?: | ||
| 'flex-start' | ||
| 'flex-end' | ||
| 'center' | ||
| 'space-between' | ||
| 'space-around' | ||
| 'space-evenly' = 'flex-start'; | ||
@property() readonly alignItems?: 'flex-start' | 'flex-end' | 'center' = | ||
'flex-start'; | ||
|
||
static styles = css` | ||
:host { | ||
--diamond-grid-gap: var(--diamond-spacing); | ||
display: flex; | ||
margin: calc(var(--diamond-grid-gap) * -0.5); | ||
} | ||
:host([inline]) { | ||
display: inline-flex; | ||
} | ||
:host([wrap='wrap']) { | ||
flex-wrap: wrap; | ||
} | ||
:host([wrap='wrap-reverse']) { | ||
flex-wrap: wrap-reverse; | ||
} | ||
${cssMap( | ||
directions, | ||
(direction) => | ||
`:host([direction="${direction}"]) { flex-direction: ${direction}; }`, | ||
)} | ||
${cssMap( | ||
justifys, | ||
(justify) => | ||
`:host([justify-content="${justify}"]) { justify-content: ${justify}; }`, | ||
)} | ||
${cssMap( | ||
aligns, | ||
(align) => `:host([align-items="${align}"]) { align-items: ${align}; }`, | ||
)} | ||
${cssMap( | ||
gaps, | ||
(gap) => | ||
`:host([gap="${gap}"]) { --diamond-grid-gap: var(--diamond-spacing-${gap}); }`, | ||
)} | ||
`; | ||
|
||
render() { | ||
return html`<slot></slot>`; | ||
} | ||
} | ||
export {}; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'diamond-grid': Grid; | ||
'diamond-grid': { | ||
wrap?: 'wrap' | 'nowrap' | 'wrap-reverse'; | ||
inline?: boolean; | ||
direction?: 'row' | 'column' | 'row-reverse' | 'column-reverse'; | ||
justifyContent?: | ||
| 'flex-start' | ||
| 'flex-end' | ||
| 'center' | ||
| 'space-between' | ||
| 'space-around' | ||
| 'space-evenly'; | ||
alignItems?: 'flex-start' | 'flex-end' | 'center'; | ||
gap?: 'xs' | 'sm' | 'lg' | 'xl'; | ||
}; | ||
} | ||
} |
Oops, something went wrong.