Skip to content

Commit

Permalink
feat: add appearance behaviors for inputs and form controls (#17565)
Browse files Browse the repository at this point in the history
* create a separate css block for filled appearance and add appearanceBehavior

* Change files

* update import order in combobox and removed unused import in textarea

* update to use appearance attribute
  • Loading branch information
khamudom authored Mar 25, 2021
1 parent 4ee640f commit 0f3e58b
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "create a separate css block for filled appearance and add appearanceBehavior",
"packageName": "@fluentui/web-components",
"email": "khamu@microsoft.com",
"dependentChangeType": "patch"
}
5 changes: 3 additions & 2 deletions packages/web-components/src/combobox/combobox.styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from '@microsoft/fast-element';
import { disabledCursor, focusVisible } from '@microsoft/fast-foundation';
import { SelectStyles } from '../select/select.styles';
import { SelectFilledStyles, SelectStyles } from '../select/select.styles';
import { appearanceBehavior } from '../utilities/behaviors';

export const ComboboxStyles = css`
${SelectStyles}
Expand Down Expand Up @@ -37,4 +38,4 @@ export const ComboboxStyles = css`
.selected-value:active {
outline: none;
}
`;
`.withBehaviors(appearanceBehavior('filled', SelectFilledStyles));
2 changes: 1 addition & 1 deletion packages/web-components/src/combobox/fixtures/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2>Default</h2>
</fluent-combobox>

<h2>Filled</h2>
<fluent-combobox id="combobox" filled>
<fluent-combobox id="combobox" appearance="filled">
<fluent-option>Please Please Me</fluent-option>
<fluent-option>With The Beatles</fluent-option>
<fluent-option>A Hard Day's Night</fluent-option>
Expand Down
49 changes: 34 additions & 15 deletions packages/web-components/src/number-field/number-field.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ import {
neutralForegroundRestBehavior,
neutralOutlineRestBehavior,
} from '../styles/index';
import { appearanceBehavior } from '../utilities/behaviors';

export const NumberFieldFilledStyles = css`
:host([appearance='filled']) .root {
background: ${neutralFillRestBehavior.var};
}
:host([appearance='filled']:hover:not([disabled])) .root {
background: ${neutralFillHoverBehavior.var};
}
`.withBehaviors(
neutralFillHoverBehavior,
neutralFillRestBehavior,
forcedColorsStylesheetBehavior(
css`
:host([appearance='filled']) .root {
background: ${SystemColors.Field};
border-color: ${SystemColors.FieldText};
}
:host([appearance='filled']:hover:not([disabled])) .root {
background: ${SystemColors.Field};
border-color: ${SystemColors.Highlight};
}
:host([appearance='filled'][disabled]) .root {
border-color: ${SystemColors.GrayText};
background: ${SystemColors.Field};
}
`,
),
);

export const NumberFieldStyles = css`
${display('inline-block')} :host {
Expand Down Expand Up @@ -140,14 +170,6 @@ export const NumberFieldStyles = css`
opacity: 1;
}
:host([appearance="filled"]) .root {
background: ${neutralFillRestBehavior.var};
}
:host([appearance="filled"]:hover:not([disabled])) .root {
background: ${neutralFillHoverBehavior.var};
}
:host([disabled]) .label,
:host([readonly]) .label,
:host([readonly]) .control,
Expand All @@ -163,6 +185,7 @@ export const NumberFieldStyles = css`
border-color: ${neutralOutlineRestBehavior.var};
}
`.withBehaviors(
appearanceBehavior('filled', NumberFieldFilledStyles),
accentFillActiveBehavior,
accentFillHoverBehavior,
accentFillRestBehavior,
Expand All @@ -175,15 +198,12 @@ export const NumberFieldStyles = css`
neutralOutlineRestBehavior,
forcedColorsStylesheetBehavior(
css`
.root,
:host([appearance='filled']) .root {
.root {
forced-color-adjust: none;
background: ${SystemColors.Field};
border-color: ${SystemColors.FieldText};
}
:host(:hover:not([disabled])) .root,
:host([appearance='filled']:hover:not([disabled])) .root,
:host([appearance='filled']:hover) .root {
:host(:hover:not([disabled])) .root {
background: ${SystemColors.Field};
border-color: ${SystemColors.Highlight};
}
Expand All @@ -209,8 +229,7 @@ export const NumberFieldStyles = css`
:host([disabled]) {
opacity: 1;
}
:host([disabled]) .root,
:host([appearance='filled']:hover[disabled]) .root {
:host([disabled]) .root {
border-color: ${SystemColors.GrayText};
background: ${SystemColors.Field};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-components/src/select/fixtures/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>Default</h2>
</fluent-select>

<h2>Filled</h2>
<fluent-select filled>
<fluent-select appearance="filled">
<fluent-option>This option has no value</fluent-option>
<fluent-option disabled>This option is disabled</fluent-option>
<fluent-option value="hi">This option has a value</fluent-option>
Expand Down
34 changes: 18 additions & 16 deletions packages/web-components/src/select/select.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ import {
neutralOutlineRestBehavior,
} from '../styles';
import { heightNumber } from '../styles/size';
import { appearanceBehavior } from '../utilities/behaviors';

export const SelectFilledStyles = css`
:host([appearance="filled"]) {
background: ${neutralFillRestBehavior.var};
border-color: transparent;
}
:host([appearance="filled"]:hover:not([disabled])) {
background: ${neutralFillHoverBehavior.var};
border-color: transparent;
}
:host([appearance="filled"]:${focusVisible}) {
border-color: ${neutralFocusBehavior.var};
}
`.withBehaviors(neutralFillHoverBehavior, neutralFillRestBehavior, neutralFocusBehavior);

export const SelectStyles = css`
${display('inline-flex')} :host {
Expand Down Expand Up @@ -183,25 +200,10 @@ export const SelectStyles = css`
::slotted([role="option"]) {
flex: 0 0 auto;
}
:host([filled]) {
background: ${neutralFillRestBehavior.var};
border-color: transparent;
}
:host([filled]:hover:not([disabled])) {
background: ${neutralFillHoverBehavior.var};
border-color: transparent;
}
:host([filled]:${focusVisible}) {
border-color: ${neutralFocusBehavior.var};
}
`.withBehaviors(
appearanceBehavior('filled', SelectFilledStyles),
accentFillHoverBehavior,
accentForegroundCutRestBehavior,
neutralFillRestBehavior,
neutralFillHoverBehavior,
neutralOutlineActiveBehavior,
neutralOutlineHoverBehavior,
neutralOutlineRestBehavior,
Expand Down
26 changes: 14 additions & 12 deletions packages/web-components/src/text-area/text-area.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import {
neutralOutlineHoverBehavior,
neutralOutlineRestBehavior,
} from '../styles';
import { appearanceBehavior } from '../utilities/behaviors';

export const TextAreaFilledStyles = css`
:host([appearance='filled']) .control {
background: ${neutralFillRestBehavior.var};
border-color: transparent;
}
:host([appearance='filled']:hover:not([disabled])) .control {
background: ${neutralFillHoverBehavior.var};
border-color: transparent;
}
`.withBehaviors(neutralFillHoverBehavior, neutralFillRestBehavior);

export const TextAreaStyles = css`
${display('inline-block')} :host {
Expand Down Expand Up @@ -52,16 +65,6 @@ export const TextAreaStyles = css`
box-shadow: 0 0 0 1px ${neutralFocusBehavior.var} inset;
}
:host(.filled) .control {
background: ${neutralFillRestBehavior.var};
border-color: transparent;
}
:host(.filled:hover:not([disabled])) .control {
background: ${neutralFillHoverBehavior.var};
border-color: transparent;
}
:host(.resize-both) .control {
resize: both;
}
Expand Down Expand Up @@ -98,10 +101,9 @@ export const TextAreaStyles = css`
opacity: var(--disabled-opacity);
}
`.withBehaviors(
neutralFillHoverBehavior,
appearanceBehavior('filled', TextAreaFilledStyles),
neutralFillInputHoverBehavior,
neutralFillInputRestBehavior,
neutralFillRestBehavior,
neutralFocusBehavior,
neutralForegroundRestBehavior,
neutralOutlineHoverBehavior,
Expand Down
55 changes: 36 additions & 19 deletions packages/web-components/src/text-field/text-field.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ import {
neutralOutlineHoverBehavior,
neutralOutlineRestBehavior,
} from '../styles';
import { appearanceBehavior } from '../utilities/behaviors';

export const TextFieldFilledStyles = css`
:host([appearance='filled']) .root {
background: ${neutralFillRestBehavior.var};
border-color: transparent;
}
:host([appearance='filled']:hover:not(.disabled)) .root {
background: ${neutralFillHoverBehavior.var};
border-color: transparent;
}
`.withBehaviors(
neutralFillHoverBehavior,
neutralFillRestBehavior,
forcedColorsStylesheetBehavior(
css`
:host([appearance='filled']) .root {
background: ${SystemColors.Field};
border-color: ${SystemColors.FieldText};
}
:host([appearance='filled']:hover:not(.disabled)) .root {
background: ${SystemColors.Field};
border-color: ${SystemColors.Highlight};
}
:host([appearance='filled'].disabled) .root {
border-color: ${SystemColors.GrayText};
background: ${SystemColors.Field};
}
`,
),
);

export const TextFieldStyles = css`
${display('inline-block')} :host {
Expand Down Expand Up @@ -100,16 +132,6 @@ export const TextFieldStyles = css`
box-shadow: 0 0 0 1px ${neutralFocusBehavior.var} inset;
}
:host(.filled) .root {
background: ${neutralFillRestBehavior.var};
border-color: transparent;
}
:host(.filled:hover:not(.disabled)) .root {
background: ${neutralFillHoverBehavior.var};
border-color: transparent;
}
:host(.disabled) .label,
:host(.readonly) .label,
:host(.readonly) .control,
Expand All @@ -121,25 +143,21 @@ export const TextFieldStyles = css`
opacity: var(--disabled-opacity);
}
`.withBehaviors(
neutralFillHoverBehavior,
appearanceBehavior('filled', TextFieldFilledStyles),
neutralFillInputHoverBehavior,
neutralFillInputRestBehavior,
neutralFillRestBehavior,
neutralFocusBehavior,
neutralForegroundRestBehavior,
neutralOutlineHoverBehavior,
neutralOutlineRestBehavior,
forcedColorsStylesheetBehavior(
css`
.root,
:host(.filled) .root {
.root {
forced-color-adjust: none;
background: ${SystemColors.Field};
border-color: ${SystemColors.FieldText};
}
:host(:hover:not(.disabled)) .root,
:host(.filled:hover:not(.disabled)) .root,
:host(.filled:hover) .root {
:host(:hover:not(.disabled)) .root {
background: ${SystemColors.Field};
border-color: ${SystemColors.Highlight};
}
Expand All @@ -150,8 +168,7 @@ export const TextFieldStyles = css`
:host(.disabled) {
opacity: 1;
}
:host(.disabled) .root,
:host(.filled:hover.disabled) .root {
:host(.disabled) .root {
border-color: ${SystemColors.GrayText};
background: ${SystemColors.Field};
}
Expand Down

0 comments on commit 0f3e58b

Please sign in to comment.