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(tailwind): first version of RefInput to show REF as radiogroup and REF_ARRAY as checkboxgroup #4585

Merged
merged 20 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
10 changes: 8 additions & 2 deletions apps/metadata-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ export interface IFieldError {
}

export type columnId = string;
export type columnValue = string | number | boolean | columnValueObject;

interface columnValueObject {
export type columnValue =
| string
| number
| boolean
| columnValueObject
| columnValueObject[];

export interface columnValueObject {
[x: string]: columnValue;
}
12 changes: 11 additions & 1 deletion apps/tailwind-components/components/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const SIZE_MAPPING = {
medium: "h-14 px-7.5 text-heading-xl gap-4",
large: "h-18 px-8.75 text-heading-xl gap-5",
};
const ICON_SIZE_MAPPING = {
tiny: 12,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no way tailwind takes care of this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's possible to add them to css/tailwind files. We would also need to refactor this component as there a lot of the javascript could be replaced by simpler tw classes. It would be good to do it in the next PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave it for now and fix in another PR

small: 18,
medium: 24,
large: 36,
};

const ICON_POSITION_MAPPING = {
left: "",
Expand All @@ -61,6 +67,10 @@ const sizeClasses = computed(() => {
const iconPositionClass = computed(() => {
return ICON_POSITION_MAPPING[props.iconPosition];
});

const iconSize = computed(() => {
return ICON_SIZE_MAPPING[props.size];
});
</script>

<template>
Expand All @@ -69,7 +79,7 @@ const iconPositionClass = computed(() => {
class="flex items-center border rounded-full"
>
<span v-if="icon">
<BaseIcon :name="icon" />
<BaseIcon :name="icon" :width="iconSize" />
</span>
<span>{{ label }}<slot /></span>
</button>
Expand Down
28 changes: 28 additions & 0 deletions apps/tailwind-components/components/button/Text.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script setup lang="ts">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to call this component? And I notice the css doesn't work on all themes properly. Need help there.

withDefaults(
defineProps<{
inverted: boolean;
icon?: string;
}>(),
{
inverted: false,
}
);
</script>

<template>
<button class="flex items-center">
<BaseIcon
v-if="icon"
:name="icon"
:class="`text-search-filter-expand${inverted ? '-mobile' : ''}`"
:width="18"
/>
<span
class="ml-2 text-body-sm hover:underline"
:class="`text-search-filter-expand${inverted ? '-mobile' : ''}`"
>
<slot />
</span>
</button>
</template>
5 changes: 4 additions & 1 deletion apps/tailwind-components/components/form/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const dirty = computed(() => !pristine.value);
const touched = ref(false);
const untouched = computed(() => !touched.value);

const hasError = computed(() => props.errors.length > 0);
const hasError = computed(() => props.errors?.length > 0);

const formFieldInput = ref<InstanceType<typeof FormFieldInput>>();

Expand Down Expand Up @@ -53,6 +53,9 @@ function validate(value: columnValue) {
:type="column.columnType"
:id="column.id"
:label="column.label"
:refSchemaId="column.refSchemaId"
:refTableId="column.refTableId"
:refLabel="column.refLabel || column.refLabelDefault"
:data="data"
:required="!!column.required"
:aria-invalid="hasError"
Expand Down
17 changes: 17 additions & 0 deletions apps/tailwind-components/components/form/FieldInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
import type {
InputString,
InputTextArea,
InputRef,
InputPlaceHolder,
} from "#build/components";
import type {
columnId,
columnValue,
CellValueType,
columnValueObject,
} from "../../../metadata-utils/src/types";

type inputComponent =
| InstanceType<typeof InputString>
| InstanceType<typeof InputTextArea>
| InstanceType<typeof InputRef>
| InstanceType<typeof InputPlaceHolder>;

defineProps<{
Expand All @@ -21,6 +24,9 @@ defineProps<{
label: string;
required: boolean;
data: columnValue;
refSchemaId?: string;
refTableId?: string;
refLabel?: string;
}>();

defineEmits(["focus", "error", "update:modelValue"]);
Expand Down Expand Up @@ -63,5 +69,16 @@ function validate(value: columnValue) {
@update:modelValue="$emit('update:modelValue', $event)"
@error="$emit('error', $event)"
></LazyInputTextArea>
<LazyInputRef
v-else-if="type === 'REF_ARRAY' || type === 'REF'"
:id="id"
:modelValue="data as columnValueObject | columnValueObject[]"
:refSchemaId="refSchemaId as string"
:refTableId="refTableId as string"
:refLabel="refLabel as string"
:isArray="type === 'REF_ARRAY'"
@update:modelValue="$emit('update:modelValue', $event)"
>
</LazyInputRef>
<LazyInputPlaceHolder v-else ref="input" :type="type" />
</template>
23 changes: 15 additions & 8 deletions apps/tailwind-components/components/input/CheckboxGroup.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<template>
<div :id="`${id}-checkbox-group`">
<div class="flex flex-row" v-for="option in checkboxOptions">
<div class="flex flex-row" v-for="option in options">
<input
type="checkbox"
:id="`${id}-${option.value}`"
:name="id"
:value="option.value"
v-model="modelValue"
:checked="modelValue!.includes(option.value)"
@input="toggleSelect"
class="sr-only"
/>
<InputLabel
Expand Down Expand Up @@ -37,23 +38,29 @@
</template>

<script lang="ts" setup>
interface checkboxDataIF {
value: string;
label?: string;
checked?: boolean | undefined;
}
import type { SelectOption } from "~/types/types";

withDefaults(
defineProps<{
id: string;
checkboxOptions: checkboxDataIF[];
options: SelectOption[];
showClearButton?: boolean;
}>(),
{
showClearButton: false,
}
);

const modelValue = defineModel<string[]>();
const emit = defineEmits(["update:modelValue", "select", "deselect"]);

function toggleSelect(event: Event) {
const target = event.target as HTMLInputElement;
if (target.checked) {
emit("select", target.value);
} else {
emit("deselect", target.value);
}
}

function resetModelValue() {
modelValue.value = [];
Expand Down
26 changes: 26 additions & 0 deletions apps/tailwind-components/components/input/GUIDELINES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Guidelines for inputs

Inputs:

- shouldn't have margins, that is up to the wrapper to apply
- should have 'script' before 'template' so the props are on top of the file

All inputs should have the following props:

- id
- modelValue
- inverted

All inputs could have the following props:

- placeholder
- hasError
- valid
- disabled
- schemaId (for backend linked inputs)
- tableId (for backend linked inputs)

N.B. the following files are not inputs and should be moved elsewhere

- Label
- Placeholder
4 changes: 2 additions & 2 deletions apps/tailwind-components/components/input/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<script lang="ts" setup>
defineProps<{
value: string;
value: any;
}>();

const modelValue = defineModel<string>();
const modelValue = defineModel<any>();
</script>
24 changes: 15 additions & 9 deletions apps/tailwind-components/components/input/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div :id="`${id}-radio-group`">
<div
class="flex justify-start align-center"
v-for="option in radioOptions"
v-for="option in options"
:key="option.value"
>
<InputRadio
Expand All @@ -11,6 +11,7 @@
:name="id"
:value="option.value"
v-model="modelValue"
@input="toggleSelect"
:checked="option.value === modelValue"
/>
<InputLabel
Expand Down Expand Up @@ -40,26 +41,31 @@
</template>

<script lang="ts" setup>
interface RadioOptionsDataIF {
value: string;
label?: string;
checked?: boolean | undefined;
}
import type { SelectOption } from "~/types/types";

withDefaults(
defineProps<{
id: string;
radioOptions: RadioOptionsDataIF[];
options: SelectOption[];
showClearButton?: boolean;
}>(),
{
showClearButton: false,
}
);

const modelValue = defineModel<string>();
const emit = defineEmits(["update:modelValue", "select", "deselect"]);

function toggleSelect(event: Event) {
const target = event.target as HTMLInputElement;
if (target.checked) {
emit("select", target.value);
} else {
emit("deselect", target.value);
}
}

function resetModelValue() {
modelValue.value = "";
modelValue.value = undefined;
}
</script>
Loading