Skip to content

refactor!: Base integer & number field styles #8949

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

Open
wants to merge 1 commit into
base: base-styles
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
107 changes: 91 additions & 16 deletions dev/integer-field.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,96 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Integer field</title>
<script type="module" src="./common.js"></script>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Integer Field</title>
<script type="module" src="./common.js"></script>

<script type="module">
import '@vaadin/integer-field';
import '@vaadin/tooltip';
</script>
</head>
<script type="module">
import '@vaadin/integer-field/src/vaadin-lit-integer-field.js';
import '@vaadin/icon/src/vaadin-lit-icon.js';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset.js';
import '@vaadin/icons';
</script>
</head>

<body>
<vaadin-integer-field label="Quantity" value="5" step-buttons-visible>
<vaadin-tooltip slot="tooltip" text="Integer field tooltip text"></vaadin-tooltip>
</vaadin-integer-field>
</body>
<body>
<section>
<h2>Plain</h2>
<vaadin-integer-field value="42"></vaadin-integer-field>
<vaadin-integer-field placeholder="Placeholder"></vaadin-integer-field>
<br><br>
<vaadin-integer-field step-buttons-visible value="42"></vaadin-integer-field>
<vaadin-integer-field placeholder="Placeholder" step-buttons-visible></vaadin-integer-field>
</section>

<section>
<h2>Bells & Whistles</h2>
<vaadin-integer-field
clear-button-visible
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Label"
required
value="42">
<span slot="prefix">€</span>
</vaadin-integer-field>
<vaadin-integer-field
clear-button-visible
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Label"
required
step-buttons-visible
value="42">
<span slot="prefix">€</span>
</vaadin-integer-field>
</section>

<section>
<h2>States</h2>
<vaadin-integer-field
clear-button-visible
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Read-only"
readonly
required
value="42">
<span slot="prefix">€</span>
</vaadin-integer-field>
<vaadin-integer-field
clear-button-visible
disabled
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Disabled"
required
value="42">
<span slot="prefix">€</span>
</vaadin-integer-field>
<br><br>
<vaadin-integer-field
clear-button-visible
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Read-only"
readonly
required
step-buttons-visible
value="42">
</vaadin-integer-field>
<vaadin-integer-field
clear-button-visible
disabled
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Disabled"
required
step-buttons-visible
value="42">
</vaadin-integer-field>
</section>
</body>
</html>
85 changes: 80 additions & 5 deletions dev/number-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,93 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Number field</title>
<title>Number Field</title>
<script type="module" src="./common.js"></script>

<script type="module">
import '@vaadin/number-field';
import '@vaadin/tooltip';
import '@vaadin/number-field/src/vaadin-lit-number-field.js';
import '@vaadin/icon/src/vaadin-lit-icon.js';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset.js';
import '@vaadin/icons';
</script>
</head>

<body>
<vaadin-number-field value="2.1" step="0.1" label="Size (kg)" step-buttons-visible>
<vaadin-tooltip slot="tooltip" text="Number field tooltip text"></vaadin-tooltip>
<section>
<h2>Plain</h2>
<vaadin-number-field value="42"></vaadin-number-field>
<vaadin-number-field placeholder="Placeholder"></vaadin-number-field>
<br><br>
<vaadin-number-field step-buttons-visible value="42"></vaadin-number-field>
<vaadin-number-field placeholder="Placeholder" step-buttons-visible></vaadin-number-field>
</section>

<section>
<h2>Bells & Whistles</h2>
<vaadin-number-field
clear-button-visible
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Label"
required
value="42">
<span slot="prefix">€</span>
</vaadin-number-field>
<vaadin-number-field
clear-button-visible
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Label"
required
step-buttons-visible
value="42">
<span slot="prefix">€</span>
</vaadin-number-field>
</section>

<section>
<h2>States</h2>
<vaadin-number-field
clear-button-visible
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Read-only"
readonly
required
value="42">
<span slot="prefix">€</span>
</vaadin-number-field>
<vaadin-number-field
clear-button-visible
disabled
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Disabled"
required
value="42">
<span slot="prefix">€</span>
</vaadin-number-field>
<br><br>
<vaadin-number-field
clear-button-visible
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Read-only"
readonly
required
step-buttons-visible
value="42">
</vaadin-number-field>
<vaadin-number-field
clear-button-visible
disabled
error-message="You need to write something in this field."
helper-text="Description for this field."
label="Disabled"
required
step-buttons-visible
value="42">
</vaadin-number-field>
</section>
</body>
</html>
2 changes: 2 additions & 0 deletions packages/component-base/src/style-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ addGlobalThemeStyles(
--vaadin-focus-ring-color: var(--_vaadin-color);

--_vaadin-icon-cross: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" /></svg>');
--_vaadin-icon-minus: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M5 12h14" /></svg>');
--_vaadin-icon-plus: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" /></svg>');
--_vaadin-icon-warn: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" /></svg>');
}

Expand Down
23 changes: 14 additions & 9 deletions packages/number-field/src/vaadin-number-field-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@
import { css } from 'lit';

export const numberFieldStyles = css`
:host([readonly]) [part$='button'] {
pointer-events: none;
:host([step-buttons-visible]) ::slotted(input) {
text-align: center;
}

[part='decrease-button']::before {
content: '\\2212';
[part='decrease-button'],
[part='increase-button'] {
background: var(--_vaadin-color-subtle);
height: var(--vaadin-icon-size, 1lh);
width: var(--vaadin-icon-size, 1lh);
}

[part='increase-button']::before {
content: '+';
[part='decrease-button'] {
mask-image: var(--_vaadin-icon-minus);
}

[part='decrease-button'],
[part='increase-button'] {
-webkit-user-select: none;
user-select: none;
mask-image: var(--_vaadin-icon-plus);
}

:host([dir='rtl']) [part='input-field'] {
direction: ltr;
}

:host([readonly]) [part$='button'] {
pointer-events: none;
}
`;
Loading