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

feat(input, input-number, input-text): add prefix and suffix width css tokens #10206

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
reflects,
renders,
t9n,
themed,
} from "../../tests/commonTests";
import { getElementRect, getElementXY, isElementFocused, selectText } from "../../tests/utils";
import { letterKeys, numberKeys } from "../../utils/key";
Expand All @@ -21,6 +22,7 @@ import {
testPostValidationFocusing,
} from "../input/common/tests";
import { assertCaretPosition } from "../../tests/utils";
import { CSS } from "./resources";

describe("calcite-input-number", () => {
const delayFor2UpdatesInMs = 200;
Expand Down Expand Up @@ -1871,4 +1873,26 @@ describe("calcite-input-number", () => {

expect(internalInput.getAttribute("inputmode")).toBe("decimal");
});

describe("theme", () => {
themed(
html`
<calcite-input-number
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input-number>
`,
{
"--calcite-input-prefix-size": {
shadowSelector: `.${CSS.prefix}`,
targetProp: "inlineSize",
},
"--calcite-input-suffix-size": {
shadowSelector: `.${CSS.suffix}`,
targetProp: "inlineSize",
},
},
);
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-input-prefix-size: Specifies the component's prefix width.
* @prop --calcite-input-suffix-size: Specifies the component's suffix width.
*/

:host {
@apply block;
}
Expand Down Expand Up @@ -250,10 +259,12 @@ input:focus {
.prefix {
@apply order-2;
border-inline-end-width: theme("borderWidth.0");
inline-size: var(--calcite-input-prefix-size, auto);
}
.suffix {
@apply order-5;
border-inline-start-width: theme("borderWidth.0");
inline-size: var(--calcite-input-suffix-size, auto);
}

// alignment type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
reflects,
renders,
t9n,
themed,
} from "../../tests/commonTests";
import { isElementFocused, selectText } from "../../tests/utils";
import {
Expand All @@ -18,6 +19,7 @@ import {
testWorkaroundForGlobalPropRemoval,
} from "../input/common/tests";
import { assertCaretPosition } from "../../tests/utils";
import { CSS } from "./resources";

describe("calcite-input-text", () => {
describe("labelable", () => {
Expand Down Expand Up @@ -501,4 +503,26 @@ describe("calcite-input-text", () => {
describe("translation support", () => {
t9n("calcite-input-text");
});

describe("theme", () => {
themed(
html`
<calcite-input-text
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input-text>
`,
{
"--calcite-input-prefix-size": {
shadowSelector: `.${CSS.prefix}`,
targetProp: "inlineSize",
},
"--calcite-input-suffix-size": {
shadowSelector: `.${CSS.suffix}`,
targetProp: "inlineSize",
},
},
);
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-input-prefix-size: Specifies the component's prefix width.
* @prop --calcite-input-suffix-size: Specifies the component's suffix width.
*/

:host {
@apply block;
}
Expand Down Expand Up @@ -292,10 +301,12 @@ input[type="text"]::-ms-reveal {
.prefix {
@apply order-2;
border-inline-end-width: theme("borderWidth.0");
inline-size: var(--calcite-input-prefix-size, auto);
}
.suffix {
@apply order-5;
border-inline-start-width: theme("borderWidth.0");
inline-size: var(--calcite-input-suffix-size, auto);
}

// alignment type
Expand Down
18 changes: 18 additions & 0 deletions packages/calcite-components/src/components/input/input.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {
renders,
hidden,
t9n,
themed,
} from "../../tests/commonTests";
import { html } from "../../../support/formatting";
import { letterKeys, numberKeys } from "../../utils/key";
import { locales, numberStringFormatter } from "../../utils/locale";
import { getElementRect, getElementXY, isElementFocused, selectText } from "../../tests/utils";
import { DEBOUNCE } from "../../utils/resources";
import { assertCaretPosition } from "../../tests/utils";
import { CSS } from "./resources";
import { testHiddenInputSyncing, testPostValidationFocusing, testWorkaroundForGlobalPropRemoval } from "./common/tests";

describe("calcite-input", () => {
Expand Down Expand Up @@ -2109,4 +2111,20 @@ describe("calcite-input", () => {
describe("translation support", () => {
t9n("calcite-input");
});

describe("theme", () => {
themed(
html` <calcite-input placeholder="Placeholder text" prefix-text="prefix" suffix-text="suffix"></calcite-input> `,
{
"--calcite-input-prefix-size": {
shadowSelector: `.${CSS.prefix}`,
targetProp: "inlineSize",
},
"--calcite-input-suffix-size": {
shadowSelector: `.${CSS.suffix}`,
targetProp: "inlineSize",
},
},
);
});
});
11 changes: 11 additions & 0 deletions packages/calcite-components/src/components/input/input.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-input-prefix-size: Specifies the component's prefix width.
* @prop --calcite-input-suffix-size: Specifies the component's suffix width.
*/

:host {
@apply block;
}
Expand Down Expand Up @@ -322,10 +331,12 @@ input[type="time"]::-webkit-clear-button {
.prefix {
@apply order-2;
border-inline-end-width: theme("borderWidth.0");
inline-size: var(--calcite-input-prefix-size, auto);
}
.suffix {
@apply order-5;
border-inline-start-width: theme("borderWidth.0");
inline-size: var(--calcite-input-suffix-size, auto);
}

// alignment type
Expand Down
6 changes: 6 additions & 0 deletions packages/calcite-components/src/custom-theme.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { chips } from "./custom-theme/chips";
import { datePicker } from "./custom-theme/date-picker";
import { dropdown } from "./custom-theme/dropdown";
import { icon } from "./custom-theme/icon";
import { input, inputTokens } from "./custom-theme/input";
import { inputNumber } from "./custom-theme/input-number";
import { inputText } from "./custom-theme/input-text";
import { loader } from "./custom-theme/loader";
import { notices } from "./custom-theme/notice";
import { pagination } from "./custom-theme/pagination";
Expand Down Expand Up @@ -96,6 +99,7 @@ const kitchenSink = (args: Record<string, string>, useTestValues = false) =>
<div style="width: 40px; height: 40px;">${actionMenu}</div>
${icon}
</div>
${input} ${inputNumber} ${inputText}
</div>
<div class="demo-column">
<div>${card}</div>
Expand All @@ -119,6 +123,7 @@ export default {
...actionPadTokens,
...actionGroupTokens,
...cardTokens,
...inputTokens,
},
};

Expand All @@ -135,6 +140,7 @@ export const theming_TestOnly = (): string => {
...actionPadTokens,
...actionGroupTokens,
...cardTokens,
...inputTokens,
},
true,
);
Expand Down
7 changes: 7 additions & 0 deletions packages/calcite-components/src/custom-theme/input-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { html } from "../../support/formatting";

export const inputNumber = html`<calcite-input-number
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input-number>`;
7 changes: 7 additions & 0 deletions packages/calcite-components/src/custom-theme/input-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { html } from "../../support/formatting";

export const inputText = html`<calcite-input-text
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input-text>`;
12 changes: 12 additions & 0 deletions packages/calcite-components/src/custom-theme/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { html } from "../../support/formatting";

export const inputTokens = {
calciteInputPrefixSize: "",
calciteInputSuffixSize: "",
};

export const input = html`<calcite-input
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input>`;
Loading