Skip to content

Commit

Permalink
Merge pull request #13 from etchteam/feature/etch-351-make-grid-into-…
Browse files Browse the repository at this point in the history
…a-non-component-component-like-wrap

Feature/etch 351 make grid into a non component component like wrap
  • Loading branch information
gavmck authored Feb 5, 2024
2 parents 4f8eccb + 32b1b00 commit 8f411bc
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 166 deletions.
99 changes: 99 additions & 0 deletions components/composition/Grid/Grid.css
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);
}
}
101 changes: 15 additions & 86 deletions components/composition/Grid/Grid.ts
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';
};
}
}
Loading

0 comments on commit 8f411bc

Please sign in to comment.