Skip to content
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

Add grid and column to web components - proposal #18034

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
1 change: 1 addition & 0 deletions packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@carbon/styles": "1.63.1",
"@floating-ui/dom": "^1.6.3",
"@ibm/telemetry-js": "^1.5.0",
"@lit/context": "1.1.3",
"flatpickr": "4.6.13",
"lit": "^3.1.0",
"lodash-es": "^4.17.21",
Expand Down
28 changes: 28 additions & 0 deletions packages/web-components/src/components/grid/column.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license
*
* Copyright IBM Corp. 2024, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { LitElement } from 'lit';
import { property } from 'lit/decorators.js';
import { carbonElement as customElement } from '../../globals/decorators/carbon-element';
import { prefix } from '../../globals/settings';

@customElement(`${prefix}-column`)
class CDSColumn extends LitElement {
/**
* Specify grid alignment. Default is center
*/
@property({ reflect: true, attribute: 'sm' })
sm = '1';

createRenderRoot() {
return this;
}
}

export default CDSColumn;
39 changes: 39 additions & 0 deletions packages/web-components/src/components/grid/defs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Button size.
*/
export enum GRID_ALIGNMENT {
/**
* Align to start.
*/
START = 'start',

/**
* Align in center
*/
CENTER = 'center',

/**
* Align to end
*/
END = 'end',
}

/**
* Button type.
*/
export enum SUB_GRID_MODE {
/**
* Default sug-grid mode.
*/
WIDE = 'wide',

/**
* Condensed sub-grid (should match hosting grid).
*/
CONDENSED = 'condensed',

/**
* Narrow sub-grid (should match hosting grid).
*/
NARROW = 'narrow',
}
8 changes: 8 additions & 0 deletions packages/web-components/src/components/grid/grid-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createContext } from '@lit/context';

export type GridContext = {
condensed: boolean;
narrow: boolean;
};

export const gridContext = createContext<GridContext>(Symbol('GridContext'));
110 changes: 110 additions & 0 deletions packages/web-components/src/components/grid/grid-story.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
@use '@carbon/styles/scss/grid';
@use '@carbon/styles/scss/colors' as *;
@use '@carbon/styles/scss/type' as *;
@use '@carbon/styles/scss/spacing' as *;

:root {
@include grid.css-grid();
}

.sb-css-grid-container {
// Gutter modes
.sb-grid::part(grid) {
background-color: $blue-20;
outline: 1px dashed $blue-40;
// row-gap: $spacing-05;
}

// .cds--css-grid p {
// @include type-style('code-02');
// }

// .cds--css-grid p:first-of-type {
// margin-block-start: 0;
// }

// Narrow
.sb-grid[narrow]::part(grid) {
background-color: #d6f9f9;
outline: 1px dashed $green-40;
}

// Condensed
.sb-grid[condensed]::part(grid) {
background-color: $purple-10;
outline: 1px dashed $purple-40;
}

.sb-sub-grid::part(grid) {
position: relative;
background: #eef4ff;
/* stylelint-disable-next-line color-named */
outline: 1px solid black;
padding-block: 2rem;
}

.sb-sub-grid::part(grid),
.sb-sub-grid[mode='wide']::part(grid) {
--grid-mode-color: #97c1ff;
}

.sb-grid[narrow]::part(grid),
.sb-sub-grid[mode='narrow']::part(grid) {
--grid-mode-color: #20d5d2;

background: $green-10;
}

.sb-grid[condensed]::part(grid),
.sb-sub-grid[mode='condensed']::part(grid) {
--grid-mode-color: #bb8eff;

background: $purple-10;
}

.sb-sub-grid[mode='narrow']::part(grid) {
background: #d6f9f9;
}

.sb-sub-grid[mode='condensed']::part(grid) {
background: #f7f2ff;
}

.sb-sub-grid::part(grid)::before {
@include type-style('code-01');

position: absolute;
display: block;
padding: 0.125rem 0.25rem;
background: var(--grid-mode-color, #97c1ff);
color: $black;
content: 'subgrid';
inset-block-start: 0;
inset-inline-start: 0;
}

// // Column
.sb-column {
--border-color: #97c1ff;

background: $white;
box-shadow: 0 0 0 1px var(--border-color);

min-block-size: 80px;
}

.sb-sub-grid[mode='narrow']::part(grid) .sb-column,
.sb-grid[narrow]::part(grid) .sb-column {
--border-color: #20d5d2;
}

.sb-sub-grid[mode='condensed']::part(grid) .sb-column,
.sb-grid[condensed]::part(grid) .sb-column {
--border-color: #bb8eff;
}
}

.cds--grid-part .sb-column .sb-grid::part(grid) {
/* stylelint-disable-next-line color-named */
box-shadow: 0 0 5px black;
}
38 changes: 38 additions & 0 deletions packages/web-components/src/components/grid/grid.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ArgTypes, Meta, Markdown } from '@storybook/blocks';
import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn';
import * as GridStories from './grid.stories';

<Meta of={GridStories} />

# Grid

> 💡 Check our
> [Stackblitz](https://stackblitz.com/github/carbon-design-system/carbon/tree/main/packages/web-components/examples/components/grid)
> example implementation.

[![Edit carbon-web-components](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/carbon-design-system/carbon/tree/main/packages/web-components/examples/components/grid)

## Getting started

Here's a quick example to get you started.

### JS (via import)

```javascript
import '@carbon/web-components/es/components/grid/index.js';
```

<Markdown>{`${cdnJs({ components: ['grid'] })}`}</Markdown>
<Markdown>{`${cdnCss()}`}</Markdown>

### HTML

```html
<cds-grid class="sb-grid"
><cds-col>1</cds-col><cds-col>1</cds-col><cds-col>1</cds-col>
</cds-grid>
```

## `<cds-grid>` attributes, properties and events

<ArgTypes of="cds-grid" />
40 changes: 40 additions & 0 deletions packages/web-components/src/components/grid/grid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Copyright IBM Corp. 2024, 2024
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//
@use '@carbon/styles/scss/config' as *;
// @use '@carbon/styles/scss/grid/css-grid' as *;
@use '@carbon/styles/scss/grid';
@use './mixin' as *;

$css-grid: #{$prefix}--css-grid;
:host(#{$prefix}-grid) .#{$prefix}--grid-part {
@extend .#{$css-grid};

box-sizing: border-box; /* prevent padding leaking out */
}

// :host(#{$prefix}-grid[align='start']) .#{$prefix}--grid-part {
// @extend .#{$css-grid}--start;
// }

// :host(#{$prefix}-grid[align='end']) .#{$prefix}--grid-part {
// @extend .#{$css-grid}--end;
// }

:host(#{$prefix}-grid[condensed]) .#{$prefix}--grid-part {
@extend .#{$css-grid}--condensed;
}

:host(#{$prefix}-grid[narrow]) .#{$prefix}--grid-part {
@extend .#{$css-grid}--narrow;
}

:host(#{$prefix}-grid[full-width]) .#{$prefix}--grid-part {
@extend .#{$css-grid}--full-width;
}

// Column styles
@include grid-columns(#{$prefix}-grid);
Loading
Loading