Skip to content

Commit

Permalink
feat(tailwind): first version of RefInput to show REF as radiogroup a…
Browse files Browse the repository at this point in the history
…nd REF_ARRAY as checkboxgroup (#4585)
  • Loading branch information
mswertz authored Jan 30, 2025
1 parent 19f80dc commit dcabeff
Show file tree
Hide file tree
Showing 26 changed files with 568 additions and 44 deletions.
2 changes: 1 addition & 1 deletion apps/metadata-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export interface IFormLegendSection {
export type columnId = string;
export type columnValue = string | number | boolean | null | columnValueObject;

interface columnValueObject {
export interface columnValueObject {
[x: string]: columnValue;
}

Expand Down
1 change: 1 addition & 0 deletions apps/tailwind-components/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
--text-color-search-button-hover: var(--text-blue-800);
--text-color-favorite: var(--color-blue-800);
--text-color-favorite-hover: var(--color-blue-800);
--text-color-button-text: var(--color-blue-800);
--text-color-search-button: var(--color-blue-500);
--text-color-search-button-hover: var(--color-blue-800);
--text-color-search-results-view-tabs: var(--color-blue-500);
Expand Down
1 change: 1 addition & 0 deletions apps/tailwind-components/assets/css/theme/aumc.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

--text-color-button-primary: var(--color-white);
--text-color-button-primary-hover: var(--color-black);
--text-color-button-text: var(--color-white);
--text-color-title: var(--color-white);
--text-color-form-header: var(--text-color-title);
--text-color-breadcrumb: var(--text-color-title);
Expand Down
1 change: 1 addition & 0 deletions apps/tailwind-components/assets/css/theme/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
--text-color-button-primary-hover: var(--color-gray-800);
--text-color-button-secondary: var(--color-green-500);
--text-color-button-secondary-hover: var(--color-green-200);
--text-color-button-text: var(--color-green-500);
--text-color-title: var(--color-white);
--text-color-title-contrast: var(--color-blue-500);
--text-color-form-header: var(--color-white);
Expand Down
1 change: 1 addition & 0 deletions apps/tailwind-components/assets/css/theme/molgenis.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
--text-color-button-outline-hover: var(--color-blue-700);
--text-color-button-disabled: var(--color-gray-600);
--text-color-button-disabled-hover: var(--color-gray-600);
--text-color-button-text: var(--color-white);
--text-color-menu: var(--color-white);
--text-color-sub-menu: var(--color-blue-500);
--text-color-sub-menu-hover: var(--color-blue-700);
Expand Down
12 changes: 10 additions & 2 deletions apps/tailwind-components/components/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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,
small: 18,
medium: 24,
large: 36,
};
const ICON_POSITION_MAPPING = {
left: "",
Expand All @@ -71,6 +77,9 @@ const iconPositionClass = computed(() => {
return ICON_POSITION_MAPPING[props.iconPosition];
});
const iconSize = computed(() => {
return ICON_SIZE_MAPPING[props.size];
});
const tooltipText = computed(() => {
return props.tooltip || props.iconOnly ? props.label : "";
});
Expand All @@ -82,8 +91,7 @@ const tooltipText = computed(() => {
class="flex items-center border rounded-input group-[.button-bar]:rounded-none group-[.button-bar]:first:rounded-l-input group-[.button-bar]:last:rounded-r-input"
:class="`${colorClasses} ${sizeClasses} ${iconPositionClass} transition-colors`"
>
<BaseIcon v-if="icon" :name="icon" />

<BaseIcon v-if="icon" :name="icon" :width="iconSize" />
<span :class="{ 'sr-only': iconOnly }">{{ label }}<slot /></span>
</button>
</template>
20 changes: 20 additions & 0 deletions apps/tailwind-components/components/button/Text.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup lang="ts">
withDefaults(
defineProps<{
inverted: boolean;
icon?: string;
}>(),
{
inverted: false,
}
);
</script>

<template>
<button class="flex items-center text-button-text">
<BaseIcon v-if="icon" :name="icon" :width="18" />
<span class="ml-2 text-body-sm hover:underline">
<slot />
</span>
</button>
</template>
4 changes: 4 additions & 0 deletions apps/tailwind-components/components/form/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
} from "../../../metadata-utils/src/types";
const props = defineProps<{
schemaId: string;
column: IColumn;
data: columnValue;
errors: IFieldError[];
Expand Down Expand Up @@ -55,6 +56,9 @@ function validate(value: columnValue) {
:type="column.columnType"
:id="column.id"
:label="column.label"
:refSchemaId="column.refSchemaId || schemaId"
: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 @@ -85,5 +91,16 @@ function validate(value: columnValue) {
@update:modelValue="$emit('update:modelValue', $event)"
@error="$emit('error', $event)"
/>
<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>
2 changes: 2 additions & 0 deletions apps/tailwind-components/components/form/Fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from "../../../metadata-utils/src/types";
const props = defineProps<{
schemaId: string;
metadata: ITableMetaData;
data: Record<columnId, columnValue>[];
}>();
Expand Down Expand Up @@ -110,6 +111,7 @@ defineExpose({ validate });
<div class="pb-8" v-for="column in chapter.columns">
<FormField
:id="`${column.id}-form-field`"
:schemaId="schemaId"
:column="column"
:data="dataMap[column.id]"
:errors="errorMap[column.id]"
Expand Down
22 changes: 15 additions & 7 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,15 +38,12 @@
</template>

<script lang="ts" setup>
interface checkboxDataIF {
value: string;
label?: string;
checked?: boolean | undefined;
}
import type { IValueLabel } from "~/types/types";
withDefaults(
defineProps<{
id: string;
checkboxOptions: checkboxDataIF[];
options: IValueLabel[];
showClearButton?: boolean;
}>(),
{
Expand All @@ -54,6 +52,16 @@ withDefaults(
);
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
3 changes: 2 additions & 1 deletion apps/tailwind-components/components/input/CheckboxIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
<rect
width="20"
height="20"
class="stroke-current"
:class="{
'fill-input': !checked && !indeterminate,
'fill-input-checked stroke-none': checked || indeterminate,
'fill-input-checked': checked || indeterminate,
}"
/>
<path
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
33 changes: 21 additions & 12 deletions apps/tailwind-components/components/input/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
'flex-col': align === 'vertical',
}"
>
<div v-for="option in radioOptions" class="flex justify-start align-center">
<div v-for="option in options" class="flex justify-start align-center">
<InputRadio
:id="`${id}-radio-group-${option.value}`"
class="sr-only fixed"
:name="id"
:value="option.value"
:modelValue="props.modelValue"
@input="$emit('update:modelValue', $event.target.value)"
:checked="option.value === props.modelValue"
v-model="modelValue"
@input="toggleSelect"
:checked="option.value === modelValue"
/>
<InputLabel
:for="`${id}-radio-group-${option.value}`"
Expand Down Expand Up @@ -46,13 +46,13 @@
</template>

<script lang="ts" setup>
import type { IRadioOptionsData } from "~/types/types";
import type { IValueLabel } from "~/types/types";
import type { columnValue } from "metadata-utils/src/types";
const props = withDefaults(
defineProps<{
id: string;
modelValue: boolean | string | null;
radioOptions: IRadioOptionsData[];
options: IValueLabel[];
showClearButton?: boolean;
align?: "horizontal" | "vertical";
}>(),
Expand All @@ -61,19 +61,28 @@ const props = withDefaults(
align: "vertical",
}
);
const modelValue = defineModel<columnValue>();
const emit = defineEmits(["update:modelValue", "select", "deselect"]);
const emit = defineEmits(["update:modelValue"]);
function toggleSelect(event: Event) {
const target = event.target as HTMLInputElement;
if (target.checked) {
emit("select", target.value);
} else {
emit("deselect", target.value);
}
}
function resetModelValue() {
emit("update:modelValue", null);
modelValue.value = undefined;
}
const isClearBtnShow = computed(() => {
return (
props.showClearButton &&
(props.modelValue === true ||
props.modelValue === false ||
(typeof props.modelValue === "string" && props.modelValue.length > 0))
(modelValue.value === true ||
modelValue.value === false ||
(modelValue.value && modelValue.value !== ""))
);
});
</script>
10 changes: 6 additions & 4 deletions apps/tailwind-components/components/input/RadioIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
r="9"
stroke-width="1"
fill="none"
class="stroke-gray-600"
class="stroke-current"
:class="{
'fill-yellow-500 stroke-none': checked,
'fill-input hover:fill-input-checked hover:stroke-none focus:fill-input-checked focus:stroke-none':
!checked,
'fill-input-checked stroke-none': checked,
}"
/>
<circle
Expand All @@ -23,10 +25,10 @@
r="3"
stroke-width="1"
stroke="none"
class="fill-transparent"
:class="{
'fill-gray-900': checked,
'!fill-gray-900': checked,
}"
v-if="checked"
/>
</svg>
</template>
Expand Down
Loading

0 comments on commit dcabeff

Please sign in to comment.