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

Toggle button #336

Merged
merged 27 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
567aed2
first pass
mollykreis Feb 2, 2022
8246296
remove base class
mollykreis Feb 2, 2022
df3480b
tests
mollykreis Feb 3, 2022
4f5cd88
move code around + fix focus style on checked toggle button
mollykreis Feb 4, 2022
bbfce5d
lint
mollykreis Feb 4, 2022
98517ec
Merge branch 'main' into toggle-button
mollykreis Feb 4, 2022
541b8fe
more moving
mollykreis Feb 7, 2022
534ab3e
Merge branch 'main' into toggle-button
mollykreis Feb 7, 2022
17ab8d1
cleanup
mollykreis Feb 7, 2022
86e00cc
lint
mollykreis Feb 7, 2022
10c901f
remove TODO
mollykreis Feb 7, 2022
e170702
Change files
mollykreis Feb 7, 2022
202aef0
update component status in readme
mollykreis Feb 7, 2022
6a40b63
add styling to button matrix & clean up test formatting
mollykreis Feb 7, 2022
f281ab7
readme for patterns directory
mollykreis Feb 7, 2022
de33f29
lint
mollykreis Feb 7, 2022
74708c8
Merge branch 'main' into toggle-button
mollykreis Feb 7, 2022
62352e5
PR feedback
mollykreis Feb 8, 2022
0cd3953
lint
mollykreis Feb 8, 2022
b551b94
Merge branch 'toggle-button' of https://github.com/ni/nimble into tog…
mollykreis Feb 8, 2022
bfa8fba
minor cleanup
mollykreis Feb 8, 2022
aac0fed
delete change file for nimble-angular
mollykreis Feb 8, 2022
b75ab75
Update packages/nimble-components/src/toggle-button/types.ts
mollykreis Feb 8, 2022
403491d
Update packages/nimble-components/src/patterns/README.md
mollykreis Feb 8, 2022
e052c95
rename button styles export
mollykreis Feb 8, 2022
5ce5ca8
Merge branch 'toggle-button' of https://github.com/ni/nimble into tog…
mollykreis Feb 8, 2022
119f2e2
apply import/export format to button types
mollykreis Feb 8, 2022
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ NOTE: To update the component status:
| Text Button | [XD](https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/42001df1-2969-438e-b353-4327d7a15102) | [:white_check_mark: - SB](https://ni.github.io/nimble/storybook/?path=/docs/button--outline-button) | :white_check_mark: | :o: |
| Text and Icon Button | [XD](https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/a378bcdb-5c4b-4298-b3b1-28d8b1a37af2) | [:white_check_mark: - SB](https://ni.github.io/nimble/storybook/?path=/docs/button--outline-button) | :white_check_mark: | :o: |
| Icon Button | [XD](https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/d022d8af-22f4-4bf2-981c-1dc0c61afece) | [:white_check_mark: - SB](https://ni.github.io/nimble/storybook/?path=/docs/button--icon-ghost-button) | :white_check_mark: | :o: |
| Toggle Icon Button | [XD](https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/d022d8af-22f4-4bf2-981c-1dc0c61afece) | :o: | :o: | :o: |
| Toggle Icon Button | [XD](https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/d022d8af-22f4-4bf2-981c-1dc0c61afece) | [:white_check_mark: - SB](https://ni.github.io/nimble/storybook/?path=/story/toggle-button--icon-button) | :o: | :o: |
| Split Icon Button | [XD](https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/d022d8af-22f4-4bf2-981c-1dc0c61afece) | :o: | :o: | :o: |
| Icon Menu Button | [XD](https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/d022d8af-22f4-4bf2-981c-1dc0c61afece) | :o: | :o: | :o: |
| Checkbox | [XD](https://xd.adobe.com/view/8ce280ab-1559-4961-945c-182955c7780b-d9b1/screen/3698340b-8162-4e5d-bf7a-20194612b3a7) | [:white_check_mark: - SB](https://ni.github.io/nimble/storybook/?path=/docs/checkbox--checkbox) | :white_check_mark: | :o: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Directive, ElementRef, Input, Renderer2 } from '@angular/core';
import type { Button } from '@ni/nimble-components/dist/esm/button';
import type { ButtonAppearanceAttribute, ButtonType } from '@ni/nimble-components/dist/esm/button/types';
import { ButtonAppearance } from '@ni/nimble-components/dist/esm/button/types';
import type { ButtonType } from '@ni/nimble-components/dist/esm/button/types';
import type { ButtonAppearanceAttribute } from '@ni/nimble-components/dist/esm/patterns/button/appearance';
import { ButtonAppearance } from '@ni/nimble-components/dist/esm/patterns/button/appearance';
import { BooleanValueOrAttribute, toBooleanProperty } from '../utilities/template-value-helpers';

export type { Button, ButtonType };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, ElementRef, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import type { Button } from '@ni/nimble-components/dist/esm/button';
import { ButtonAppearance } from '@ni/nimble-components/dist/esm/button/types';
import { ButtonAppearance } from '@ni/nimble-components/dist/esm/patterns/button/appearance';
import type { BooleanValueOrAttribute } from '../../utilities/template-value-helpers';
import { NimbleButtonDirective } from '../nimble-button.directive';
import { NimbleButtonModule } from '../nimble-button.module';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Update import paths for button appearance",
"packageName": "@ni/nimble-angular",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Create nimble-toggle-button",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion packages/nimble-components/src/button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DesignSystem
} from '@microsoft/fast-foundation';
import { styles } from './styles';
mollykreis marked this conversation as resolved.
Show resolved Hide resolved
import { ButtonAppearance } from './types';
import { ButtonAppearance } from '../patterns/button/appearance';

export type { Button };

Expand Down
217 changes: 3 additions & 214 deletions packages/nimble-components/src/button/styles.ts
Original file line number Diff line number Diff line change
@@ -1,217 +1,6 @@
import { css } from '@microsoft/fast-element';
import { display } from '@microsoft/fast-foundation';
import { focusVisible } from '../utilities/style/focus';
import {
actionColorRgbPartial,
borderColorHover,
borderColorRgbPartial,
borderWidth,
buttonContentFontColor,
contentFontColorDisabled,
contentFontSize,
controlHeight,
fillColorSelected,
fontFamily,
iconColor,
smallDelay,
standardPadding
} from '../theme-provider/design-tokens';
import { appearanceBehavior } from './behaviors';
import { ButtonAppearance } from './types';
import { buttonStyles } from '../patterns/button/styles';

export const styles = css`
${display('inline-flex')}

:host {
background-color: transparent;
height: ${controlHeight};
color: ${buttonContentFontColor};
font-family: ${fontFamily};
font-size: ${contentFontSize};
cursor: pointer;
outline: none;
border: none;
box-sizing: border-box;
${
/*
Not sure why but this is needed to get buttons with icons and buttons
without icons to align on the same line when the button is inline-flex
See: https://github.com/microsoft/fast/issues/5414
*/ ''
}
vertical-align: middle;
}

:host([disabled]) {
color: ${contentFontColorDisabled};
cursor: default;
}

.control {
background-color: transparent;
height: inherit;
width: inherit;
border: ${borderWidth} solid transparent;
box-sizing: border-box;
color: inherit;
border-radius: inherit;
fill: inherit;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 4px;
cursor: inherit;
font-family: inherit;
font-size: inherit;
outline: none;
margin: 0;
padding: 0 ${standardPadding};
transition: box-shadow ${smallDelay};
}

:host([content-hidden]) .control {
width: ${controlHeight};
padding: 0px;
}

@media (prefers-reduced-motion) {
.control {
transition-duration: 0s;
}
}

.control:hover {
box-shadow: 0px 0px 0px ${borderWidth} ${borderColorHover} inset;
outline: none;
}

.control${focusVisible} {
box-shadow: 0px 0px 0px ${borderWidth} ${borderColorHover} inset;
outline: ${borderWidth} solid ${borderColorHover};
outline-offset: -4px;
}

.control:active {
box-shadow: none;
outline: none;
}

.control[disabled] {
box-shadow: none;
outline: none;
}

.content {
display: contents;
}

:host([content-hidden]) .content {
display: none;
}

[part='start'] {
display: contents;
}

slot[name='start']::slotted(*) {
${iconColor.cssCustomProperty}: ${buttonContentFontColor};
}

:host([disabled]) slot[name='start']::slotted(*) {
opacity: 0.6;
}

[part='end'] {
display: none;
}
`
// prettier-ignore
.withBehaviors(
appearanceBehavior(
ButtonAppearance.Outline,
css`
.control {
background-color: transparent;
border-color: rgba(${actionColorRgbPartial}, 0.5);
}

.control:hover {
background-color: transparent;
border-color: ${borderColorHover};
}

.control${focusVisible} {
background-color: transparent;
border-color: ${borderColorHover};
}

.control:active {
background-color: ${fillColorSelected};
border-color: transparent;
}

.control[disabled] {
background-color: transparent;
border-color: rgba(${borderColorRgbPartial}, 0.2);
}
`
),
appearanceBehavior(
ButtonAppearance.Ghost,
css`
.control {
background-color: transparent;
border-color: transparent;
}

.control:hover {
background-color: transparent;
border-color: ${borderColorHover};
}

.control${focusVisible} {
background-color: transparent;
border-color: ${borderColorHover};
}

.control:active {
background-color: ${fillColorSelected};
border-color: transparent;
}

.control[disabled] {
background-color: transparent;
border-color: transparent;
}
`
),
appearanceBehavior(
ButtonAppearance.Block,
css`
.control {
background-color: rgba(${borderColorRgbPartial}, 0.1);
border-color: transparent;
}

.control:hover {
background-color: rgba(${borderColorRgbPartial}, 0.1);
border-color: ${borderColorHover};
}

.control${focusVisible} {
background-color: rgba(${borderColorRgbPartial}, 0.1);
border-color: ${borderColorHover};
}

.control:active {
background-color: ${fillColorSelected};
border-color: transparent;
}

.control[disabled] {
background-color: rgba(${borderColorRgbPartial}, 0.1);
border-color: rgba(${borderColorRgbPartial}, 0.1);
}
`
)
);
${buttonStyles}
`;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, Story } from '@storybook/html';
import { withXD } from 'storybook-addon-xd-designs';
import { html, ViewTemplate, when } from '@microsoft/fast-element';
import { ButtonAppearance } from '../types';
import { ButtonAppearance } from '../../patterns/button/appearance';
import {
disabledStates,
DisabledState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/html';
import { withXD } from 'storybook-addon-xd-designs';
import { html, when } from '@microsoft/fast-element';
import { ButtonAppearance } from '../types';
import { ButtonAppearance } from '../../patterns/button/appearance';
import '..';
import '../../icons/access-control';
import { createRenderer } from '../../utilities/tests/storybook';
Expand Down
9 changes: 1 addition & 8 deletions packages/nimble-components/src/button/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
/**
* Types of button appearance.
* Types of button.
* @public
*/
import type { Button } from '@microsoft/fast-foundation';

export enum ButtonAppearance {
mollykreis marked this conversation as resolved.
Show resolved Hide resolved
Outline = 'outline',
Ghost = 'ghost',
Block = 'block'
}
export type ButtonAppearanceAttribute = `${ButtonAppearance}`;

export type ButtonType = Button['type'];
1 change: 1 addition & 0 deletions packages/nimble-components/src/patterns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The `patterns` directory contains patterns, such as styles and types, that are shared between multiple components. Place each pattern in its own sub-directory.
mollykreis marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions packages/nimble-components/src/patterns/button/appearance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
mollykreis marked this conversation as resolved.
Show resolved Hide resolved
* Types of button appearance.
* @public
*/
export enum ButtonAppearance {
Outline = 'outline',
Ghost = 'ghost',
Block = 'block'
}
export type ButtonAppearanceAttribute = `${ButtonAppearance}`;
Loading