-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@next] port deprecated (2.x) button for backwards compatibility (#454)
- Loading branch information
Showing
13 changed files
with
818 additions
and
2 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
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
49 changes: 49 additions & 0 deletions
49
src/lib/deprecated/button/deprecated-button-component-delegate.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,49 @@ | ||
import { BaseComponentDelegate, IBaseComponentDelegateConfig, IBaseComponentDelegateOptions } from '../../core/delegates/base-component-delegate'; | ||
import { IDeprecatedButtonComponent } from './deprecated-button'; | ||
import { DEPRECATED_BUTTON_CONSTANTS } from './deprecated-button-constants'; | ||
|
||
export type DeprecatedButtonComponentDelegateProps = Partial<IDeprecatedButtonComponent>; | ||
export interface IDeprecatedButtonComponentDelegateOptions extends IBaseComponentDelegateOptions { | ||
type?: 'button' | 'submit'; | ||
text?: string; | ||
} | ||
export interface IDeprecatedButtonComponentDelegateConfig extends IBaseComponentDelegateConfig<IDeprecatedButtonComponent, IDeprecatedButtonComponentDelegateOptions> {} | ||
|
||
export class DeprecatedButtonComponentDelegate extends BaseComponentDelegate<IDeprecatedButtonComponent, IDeprecatedButtonComponentDelegateOptions> { | ||
private _buttonElement?: HTMLButtonElement; | ||
|
||
constructor(config?: IDeprecatedButtonComponentDelegateConfig) { | ||
super(config); | ||
} | ||
|
||
public override destroy(): void { | ||
this._buttonElement = undefined; | ||
} | ||
|
||
public get buttonElement(): HTMLButtonElement | undefined { | ||
return this._buttonElement; | ||
} | ||
|
||
protected _build(): IDeprecatedButtonComponent { | ||
const component = document.createElement(DEPRECATED_BUTTON_CONSTANTS.elementName); | ||
|
||
this._buttonElement = document.createElement('button'); | ||
this._buttonElement.type = this._config.options?.type || 'button'; | ||
this._buttonElement.textContent = this._config.options?.text || ''; | ||
component.appendChild(this._buttonElement); | ||
|
||
return component; | ||
} | ||
|
||
public onClick(listener: (evt: MouseEvent) => void): void { | ||
this._buttonElement?.addEventListener('click', listener); | ||
} | ||
|
||
public onFocus(listener: (evt: Event) => void): void { | ||
this._buttonElement?.addEventListener('focus', evt => listener(evt)); | ||
} | ||
|
||
public onBlur(listener: (evt: Event) => void): void { | ||
this._buttonElement?.addEventListener('blur', evt => listener(evt)); | ||
} | ||
} |
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,21 @@ | ||
import { COMPONENT_NAME_PREFIX } from '../../constants'; | ||
|
||
const elementName: keyof HTMLElementTagNameMap = `${COMPONENT_NAME_PREFIX}deprecated-button`; | ||
|
||
const attributes = { | ||
TYPE: 'type', | ||
DISABLED: 'disabled', | ||
FULL_WIDTH: 'full-width' | ||
}; | ||
|
||
const selectors = { | ||
BUTTON: 'button,a' | ||
}; | ||
|
||
export const DEPRECATED_BUTTON_CONSTANTS = { | ||
elementName, | ||
attributes, | ||
selectors | ||
}; | ||
|
||
export type DeprecatedButtonType = 'text' | 'raised' | 'unelevated' | 'outlined' | 'dense'; |
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,5 @@ | ||
<template> | ||
<slot></slot> | ||
<forge-focus-indicator part="focus-indicator"></forge-focus-indicator> | ||
<forge-state-layer exportparts="surface:state-layer"></forge-state-layer> | ||
</template> |
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,128 @@ | ||
@use '../../button/core' as *; | ||
@use '../../state-layer'; | ||
@use '../../focus-indicator'; | ||
|
||
// | ||
// Host | ||
// | ||
|
||
:host { | ||
@include tokens; | ||
} | ||
|
||
:host { | ||
@include host; | ||
|
||
border-radius: #{token(shape)}; | ||
} | ||
|
||
:host([hidden]) { | ||
display: none; | ||
} | ||
|
||
// | ||
// Base | ||
// | ||
|
||
::slotted(:is(button,a)) { | ||
@include base; | ||
|
||
--forge-icon-font-size: 1.25em; | ||
} | ||
|
||
::slotted(a) { | ||
text-decoration: none; | ||
--forge-typography-link-text-decoration: none; | ||
} | ||
|
||
forge-state-layer { | ||
@include state-layer.provide-theme(( color: #{token(color)} )); | ||
} | ||
|
||
forge-focus-indicator { | ||
@include focus-indicator.provide-theme(( | ||
color: #{token(primary-color)}, | ||
outward-offset: #{token(focus-indicator-offset)} | ||
)); | ||
} | ||
|
||
// | ||
// Types | ||
// | ||
|
||
:host(:is(:not([type],[type*=text]))) { | ||
::slotted(:is(button,a)) { | ||
@include text; | ||
} | ||
} | ||
|
||
:host(:is([type*=unelevated],[type*=raised])) { | ||
::slotted(:is(button,a)) { | ||
@include filled; | ||
} | ||
|
||
forge-state-layer { | ||
@include state-layer.provide-theme(( color: #{token(filled-color)} )); | ||
} | ||
} | ||
|
||
:host([type*=raised]) { | ||
::slotted(:is(button,a)) { | ||
@include raised; | ||
} | ||
} | ||
|
||
:host([type*=outlined]) { | ||
::slotted(:is(button,a)) { | ||
@include outlined; | ||
} | ||
} | ||
|
||
// | ||
// Full width | ||
// | ||
|
||
:host([full-width]) { | ||
width: 100%; | ||
} | ||
|
||
|
||
// | ||
// Dense | ||
// | ||
|
||
:host(:is([dense],[type*=dense])) { | ||
::slotted(:is(button,a)) { | ||
@include dense; | ||
} | ||
} | ||
|
||
// | ||
// Disabled | ||
// | ||
|
||
:host([disabled]) { | ||
@include host-disabled; | ||
|
||
::slotted(button[disabled]) { | ||
@include disabled; | ||
} | ||
} | ||
|
||
:host([type*=outlined][disabled]) { | ||
::slotted(button[disabled]) { | ||
@include outlined-disabled; | ||
} | ||
} | ||
|
||
:host(:is([type*=unelevated],[type*=raised])[disabled]) { | ||
::slotted(button[disabled]) { | ||
@include filled-disabled; | ||
} | ||
} | ||
|
||
:host([type*=raised][disabled]) { | ||
::slotted(button[disabled]) { | ||
@include raised-disabled; | ||
} | ||
} |
Oops, something went wrong.