Skip to content

Commit

Permalink
feat(text-field): styled read-only attribute w/ tokens (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
nowseemee authored May 6, 2021
1 parent 37947be commit 1abbdd6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
24 changes: 20 additions & 4 deletions packages/components/src/components/text-field/text-field.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ scale-text-field {
--spacing-x: var(--scl-spacing-12);
--color-disabled: var(--scl-color-background-disabled);
--background-disabled: var(--scl-color-white);
--border-color-readonly: var(--scl-color-grey-0);
--background-readonly: var(--scl-color-grey-0);

/*meta*/
--font-weight-meta: var(--scl-font-weight-bold);
Expand Down Expand Up @@ -57,6 +59,7 @@ scale-text-field {

/*label*/
--color-label: var(--scl-color-grey-60);
--color-label-readonly: var(--scl-color-text-standard);
--z-index-label: var(--scl-z-index-10);
--transition-label: var(--transition);
--font-size-label: var(--scl-font-size-16);
Expand Down Expand Up @@ -113,11 +116,13 @@ scale-text-field {
color: var(--color-meta);
}

.text-field:not(.text-field--disabled) .text-field__control:hover {
.text-field:not(.text-field--disabled):not(.text-field--readonly)
.text-field__control:hover {
border-color: var(--border-color-hover);
}

.text-field:not(.text-field--disabled) .text-field__control:focus {
.text-field:not(.text-field--disabled):not(.text-field--readonly)
.text-field__control:focus {
border-color: var(--border-color-focus);
box-shadow: var(--box-shadow-focus);
}
Expand Down Expand Up @@ -148,7 +153,7 @@ scale-text-field {
);
font-weight: var(--font-weight-label);
}
.text-field--has-focus .text-field__label,
.text-field--has-focus:not(.text-field--readonly) .text-field__label,
.animated .text-field__label {
transform: translate(var(--spacing-x), var(--scl-spacing-8));
font-size: var(--font-size-label-focus);
Expand All @@ -174,14 +179,25 @@ scale-text-field {
);
font-weight: var(--font-weight-label-small);
}
.text-field--size-small.text-field--has-focus .text-field__label,
.text-field--size-small.text-field--has-focus:not(.text-field--readonly)
.text-field__label,
.text-field--size-small.animated .text-field__label {
transform: translate(var(--spacing-x), var(--scl-spacing-4));
font-size: var(--font-size-label-focus);
}
.text-field--transparent .text-field__control {
background-color: transparent;
}
.text-field--readonly input,
.text-field--readonly .text-field__control {
color: var(--color-label-readonly);
border-color: var(--border-color-readonly);
background: var(--background-readonly);
}

.text-field--readonly .text-field__control:focus {
box-shadow: var(--box-shadow-focus);
}

.text-field--disabled label,
.text-field--disabled .text-field__label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export class TextField {
this.transparent && 'text-field--transparent',
this.status && `text-field--status-${this.status}`,
this.size && `text-field--size-${this.size}`,
this.readonly && `text-field--readonly`,
animated && 'animated'
);
}
Expand Down
17 changes: 17 additions & 0 deletions packages/components/src/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,23 @@ <h3>Input Text - disabled</h3>
label="input text disabled"
></scale-text-field>

<h3>Input Text - read only</h3>
<scale-text-field
type="string"
label="input text read only"
value="hello"
readonly
></scale-text-field>

<h3>Input Text - read only empty</h3>

<scale-text-field
type="string"
label="input text read only empty"
readonly
></scale-text-field>

<h3>Input Text - small</h3>
<scale-text-field type="email" label="email"></scale-text-field>
<scale-text-field type="number" label="number"></scale-text-field>
<scale-text-field type="password" label="password"></scale-text-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ scale-text-field {
--spacing-x: var(--scl-spacing-12);
--color-disabled: var(--scl-color-background-disabled);
--background-disabled: var(--scl-color-white);
--border-color-readonly: var(--scl-color-grey-0);
--background-readonly: var(--scl-color-grey-0);

/*meta*/
--font-weight-meta: var(--scl-font-weight-bold);
Expand Down Expand Up @@ -136,6 +138,7 @@ scale-text-field {

/*label*/
--color-label: var(--scl-color-grey-60);
--color-label-readonly: var(--scl-color-text-standard);
--z-index-label: var(--scl-z-index-10);
--transition-label: var(--transition);
--font-size-label: var(--scl-font-size-16);
Expand Down Expand Up @@ -261,14 +264,13 @@ scale-text-field {
```


<!--
## Readonly
## Readonly

<Canvas withSource="none">
<Story
name="Readonly"
name="Read Only"
args={{
label: "Readonly",
label: "Read only",
readonly: true,
value: "This cannot be changed"
}}
Expand All @@ -278,9 +280,8 @@ scale-text-field {
</Canvas>

```html
<scale-text-field label="Readonly" value="This cannot be changed" readonly></scale-text-field>
<scale-text-field label="Read only" value="This cannot be changed" readonly></scale-text-field>
```
-->


## Max Length With Counter
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/visual-tests/src/textfield.visual.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('Textfield', () => {
['helper-text'],
['with-error'],
['disabled'],
['read-only'],
['small'],
['max-length-with-counter'],
])('%p', async (variant) => {
Expand Down

0 comments on commit 1abbdd6

Please sign in to comment.