Skip to content

Commit

Permalink
feat(divider): add divider component
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 504300015
  • Loading branch information
asyncLiz authored and copybara-github committed Jan 24, 2023
1 parent f3273e6 commit 9431c16
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
6 changes: 6 additions & 0 deletions divider/_divider.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

@forward './lib/divider' show theme;
31 changes: 31 additions & 0 deletions divider/divider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {customElement} from 'lit/decorators.js';

import {Divider} from './lib/divider.js';
import {styles} from './lib/divider-styles.css.js';

declare global {
interface HTMLElementTagNameMap {
'md-divider': MdDivider;
}
}

/**
* @summary A divider is a thin line that groups content in lists and
* containers.
*
* @description Dividers can reinforce tapability, such as when used to separate
* list items or define tappable regions in an accordion.
*
* @final
* @suppress {visibility}
*/
@customElement('md-divider')
export class MdDivider extends Divider {
static override styles = [styles];
}
48 changes: 48 additions & 0 deletions divider/lib/_divider.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

@use '../../sass/theme';
@use '../../tokens';

@mixin theme($tokens) {
$tokens: theme.validate-theme(tokens.md-comp-divider-values(), $tokens);
$tokens: theme.create-theme-vars($tokens, 'divider');

@include theme.emit-theme-vars($tokens);
}

@mixin styles() {
$tokens: tokens.md-comp-divider-values();
$tokens: theme.create-theme-vars($tokens, 'divider');

:host {
@each $token, $value in $tokens {
--_#{$token}: #{$value};
}

box-sizing: border-box;
color: var(--_color);
display: flex;
height: var(--_thickness);
width: 100%;
}

:host([inset]),
:host([inset-start]) {
padding-inline-start: 16px;
}

:host([inset]),
:host([inset-end]) {
padding-inline-end: 16px;
}

:host::before {
background: currentColor;
content: '';
height: 100%;
width: 100%;
}
}
8 changes: 8 additions & 0 deletions divider/lib/divider-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

@use './divider';

@include divider.styles;
30 changes: 30 additions & 0 deletions divider/lib/divider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {LitElement} from 'lit';
import {property} from 'lit/decorators.js';

/**
* A divider component.
*/
export class Divider extends LitElement {
/**
* Indents the divider with equal padding on both sides.
*/
@property({type: Boolean, reflect: true}) inset = false;

/**
* Indents the divider with padding on the leading side.
*/
@property({type: Boolean, reflect: true, attribute: 'inset-start'})
insetStart = false;

/**
* Indents the divider with padding on the trailing side.
*/
@property({type: Boolean, reflect: true, attribute: 'inset-end'})
insetEnd = false;
}

0 comments on commit 9431c16

Please sign in to comment.