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

fix(textfield/textarea): clean up classes #163

Merged
merged 8 commits into from
May 14, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install pnpm and dependencies
uses: pnpm/action-setup@v2
with:
version: 8
version: 9
run_install: true
- name: Validate extracted messages
run: pnpm messages:compile
2 changes: 1 addition & 1 deletion .github/workflows/lint.pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install pnpm and dependencies
uses: pnpm/action-setup@v2
with:
version: 8
version: 9
run_install: true
- name: Lint
run: pnpm lint:check
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install pnpm and dependencies
uses: pnpm/action-setup@v2
with:
version: 8
version: 9
run_install: true
- name: Build
run: pnpm build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install pnpm and dependencies
uses: pnpm/action-setup@v2
with:
version: 8
version: 9
run_install: true
- name: Test
run: pnpm test
25 changes: 9 additions & 16 deletions components/forms/w-textarea.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<template>
<w-field v-bind="{ ...$attrs, ...$props }" #default="{ triggerValidation, aria, hasValidationErrors }">
<div :class="wrapperClass">
<div :class="[ccInput.wrapper]">
<textarea
:class="[
inputClasses,
{
[ccInput.invalid]: hasValidationErrors,
}
]"
:class="{
[`${ccInput.base} ${ccInput.textArea}`]: true,
[ccInput.placeholder]: !!p.placeholder,
[ccInput.default]: !hasValidationErrors && !p.disabled && !p.readOnly,
[ccInput.invalid]: hasValidationErrors && !p.disabled && !p.readOnly,
[ccInput.disabled]: !hasValidationErrors && p.disabled && !p.readOnly,
[ccInput.readOnly]: !hasValidationErrors && !p.disabled && p.readOnly,
}"
:disabled="disabled"
:readOnly="readOnly"
v-bind="{ ...aria, ...$attrs, class: '' }" v-model="model" :id="id" @blur="triggerValidation"
Expand All @@ -17,22 +19,13 @@
</template>

<script setup>
import { computed } from 'vue';
import { input as ccInput } from '@warp-ds/css/component-classes';
import { createModel } from 'create-v-model';
import { default as wField, fieldProps } from './w-field.vue';

const p = defineProps(fieldProps);
const emit = defineEmits(['update:modelValue']);
const model = createModel({ props: p, emit });

const wrapperClass = ccInput.wrapper;
const inputClasses = computed(() => ({
[`${ccInput.default} ${ccInput.textArea}`]: true,
[ccInput.disabled]: p.disabled,
[ccInput.readOnly]: p.readOnly,
[ccInput.placeholder]: !!p.placeholder,
}));
</script>

<script>
Expand Down
46 changes: 21 additions & 25 deletions components/forms/w-textfield.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { ref, computed, useSlots } from 'vue';
import { ref, useSlots } from 'vue';
import { input as ccInput } from '@warp-ds/css/component-classes';
import { createModel } from 'create-v-model';
import { setupMask } from './w-input-mask.js';
Expand All @@ -24,18 +24,7 @@ const slots = useSlots();
const model = createModel({ props: p, emit });
const inputEl = ref(null);
if (p.mask) setupMask({ props: p, emit, inputEl });
const inputClasses = computed(() => ({
[ccInput.default]: true,
[ccInput.disabled]: p.disabled,
[ccInput.readOnly]: p.readOnly,
[ccInput.placeholder]: !!p.placeholder,
[ccInput.suffix]: slots.suffix,
[ccInput.prefix]: slots.prefix,
}));

const inputWithPrefixStyle = computed(() => (
slots.prefix ? 'padding-left: var(--w-prefix-width, 40px);' : undefined
))
</script>

<template>
Expand All @@ -47,12 +36,16 @@ const inputWithPrefixStyle = computed(() => (
:id="id"
ref="inputEl"
:type="type"
:class="[
inputClasses,
{
[ccInput.invalid]: hasValidationErrors,
}
]"
:class="{
[ccInput.base]: true,
[ccInput.default]: !hasValidationErrors && !p.disabled && !p.readOnly,
[ccInput.invalid]: hasValidationErrors && !p.disabled && !p.readOnly,
[ccInput.disabled]: !hasValidationErrors && p.disabled && !p.readOnly,
[ccInput.readOnly]: !hasValidationErrors && !p.disabled && p.readOnly,
[ccInput.placeholder]: !!p.placeholder,
[ccInput.suffix]: slots.suffix,
[ccInput.prefix]: slots.prefix
}"
:autocomplete="autocomplete"
:disabled="disabled"
:placeholder="placeholder"
Expand All @@ -65,19 +58,22 @@ const inputWithPrefixStyle = computed(() => (
ref="inputEl"
v-model="model"
:type="type"
:class="[
inputClasses,
{
[ccInput.invalid]: hasValidationErrors,
}
]"
:class="{
[ccInput.base]: true,
[ccInput.default]: !hasValidationErrors && !p.disabled && !p.readOnly,
[ccInput.invalid]: hasValidationErrors && !p.disabled && !p.readOnly,
[ccInput.disabled]: !hasValidationErrors && p.disabled && !p.readOnly,
[ccInput.readOnly]: !hasValidationErrors && !p.disabled && p.readOnly,
[ccInput.placeholder]: !!p.placeholder,
[ccInput.suffix]: slots.suffix,
[ccInput.prefix]: slots.prefix
}"
:autocomplete="autocomplete"
:disabled="disabled"
:placeholder="placeholder"
:readOnly="readOnly"
v-bind="{ ...aria, ...$attrs, class: '' }"
@blur="triggerValidation"
:style="inputWithPrefixStyle"
>
<slot name="suffix" :inputElement="inputEl" />
</div>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"dependencies": {
"@lingui/core": "^4.7.0",
"@warp-ds/core": "^1.1.1",
"@warp-ds/css": "1.9.3",
"@warp-ds/css": "1.9.6",
"@warp-ds/icons": "2.0.0",
"@warp-ds/uno": "1.10.2",
"@warp-ds/uno": "1.12.0",
"create-v-model": "^2.2.0",
"dom-focus-lock": "^1.1.0",
"element-collapse": "^1.1.0",
Expand Down
Loading
Loading