From 8154312bf87af0a817dfdb88d4ddd8bc0be885b8 Mon Sep 17 00:00:00 2001 From: Jonathan Carle Date: Mon, 30 Sep 2024 14:38:01 +0200 Subject: [PATCH 01/24] implement onyxform with form-context --- .../src/components/OnyxButton/OnyxButton.vue | 6 +- .../src/components/OnyxButton/types.ts | 3 +- .../components/OnyxCheckbox/OnyxCheckbox.vue | 8 +- .../OnyxCheckboxGroup/OnyxCheckboxGroup.vue | 7 +- .../src/components/OnyxCheckboxGroup/types.ts | 3 +- .../components/OnyxForm/OnyxForm.stories.ts | 46 ++++++++ .../src/components/OnyxForm/OnyxForm.ts | 102 ++++++++++++++++++ .../src/components/OnyxForm/OnyxForm.vue | 28 +++++ .../sit-onyx/src/components/OnyxForm/types.ts | 4 + .../OnyxIconButton/OnyxIconButton.vue | 6 +- .../src/components/OnyxIconButton/types.ts | 3 +- .../src/components/OnyxInput/OnyxInput.vue | 11 +- .../src/components/OnyxInput/types.ts | 5 +- .../OnyxRadioButton/OnyxRadioButton.vue | 8 +- .../OnyxRadioGroup/OnyxRadioGroup.vue | 6 +- .../src/components/OnyxRadioGroup/types.ts | 3 +- .../src/components/OnyxSelect/OnyxSelect.vue | 3 + .../src/components/OnyxSelect/types.ts | 11 +- .../components/OnyxStepper/OnyxStepper.vue | 18 ++-- .../src/components/OnyxStepper/types.ts | 5 +- .../src/components/OnyxSwitch/OnyxSwitch.vue | 9 +- .../src/components/OnyxSwitch/types.ts | 3 +- .../components/OnyxTextarea/OnyxTextarea.vue | 11 +- packages/sit-onyx/src/types/components.ts | 5 +- 24 files changed, 267 insertions(+), 47 deletions(-) create mode 100644 packages/sit-onyx/src/components/OnyxForm/OnyxForm.stories.ts create mode 100644 packages/sit-onyx/src/components/OnyxForm/OnyxForm.ts create mode 100644 packages/sit-onyx/src/components/OnyxForm/OnyxForm.vue create mode 100644 packages/sit-onyx/src/components/OnyxForm/types.ts diff --git a/packages/sit-onyx/src/components/OnyxButton/OnyxButton.vue b/packages/sit-onyx/src/components/OnyxButton/OnyxButton.vue index 7c1f46b591..c66a1e0156 100644 --- a/packages/sit-onyx/src/components/OnyxButton/OnyxButton.vue +++ b/packages/sit-onyx/src/components/OnyxButton/OnyxButton.vue @@ -6,9 +6,10 @@ import OnyxLoadingIndicator from "../OnyxLoadingIndicator/OnyxLoadingIndicator.v import OnyxRipple from "../OnyxRipple/OnyxRipple.vue"; import OnyxSkeleton from "../OnyxSkeleton/OnyxSkeleton.vue"; import type { OnyxButtonProps } from "./types"; +import { FORM_INJECTED_SYMBOL, useFormContext } from "../OnyxForm/OnyxForm"; const props = withDefaults(defineProps(), { - disabled: false, + disabled: FORM_INJECTED_SYMBOL, loading: false, type: "button", color: "primary", @@ -17,6 +18,7 @@ const props = withDefaults(defineProps(), { }); const { densityClass } = useDensity(props); +const { disabled } = useFormContext(props); const rippleRef = ref>(); const rippleEvents = computed(() => rippleRef.value?.events ?? {}); @@ -33,7 +35,7 @@ const rippleEvents = computed(() => rippleRef.value?.events ?? {}); { 'onyx-button--loading': props.loading }, densityClass, ]" - :disabled="props.disabled || props.loading" + :disabled="disabled || props.loading" :type="props.type" :aria-label="props.loading ? props.label : undefined" :autofocus="props.autofocus" diff --git a/packages/sit-onyx/src/components/OnyxButton/types.ts b/packages/sit-onyx/src/components/OnyxButton/types.ts index b88066472b..f19a72913d 100644 --- a/packages/sit-onyx/src/components/OnyxButton/types.ts +++ b/packages/sit-onyx/src/components/OnyxButton/types.ts @@ -1,5 +1,6 @@ import type { DensityProp } from "../../composables/density"; import type { AutofocusProp } from "../../types"; +import type { FormInjected } from "../OnyxForm/OnyxForm"; export type OnyxButtonProps = DensityProp & AutofocusProp & { @@ -10,7 +11,7 @@ export type OnyxButtonProps = DensityProp & /** * If the button should be disabled or not. */ - disabled?: boolean; + disabled?: FormInjected; /** * Shows a loading indicator. */ diff --git a/packages/sit-onyx/src/components/OnyxCheckbox/OnyxCheckbox.vue b/packages/sit-onyx/src/components/OnyxCheckbox/OnyxCheckbox.vue index 009bc088df..ceb934cd20 100644 --- a/packages/sit-onyx/src/components/OnyxCheckbox/OnyxCheckbox.vue +++ b/packages/sit-onyx/src/components/OnyxCheckbox/OnyxCheckbox.vue @@ -8,11 +8,12 @@ import OnyxErrorTooltip from "../OnyxErrorTooltip/OnyxErrorTooltip.vue"; import OnyxLoadingIndicator from "../OnyxLoadingIndicator/OnyxLoadingIndicator.vue"; import OnyxSkeleton from "../OnyxSkeleton/OnyxSkeleton.vue"; import type { OnyxCheckboxProps } from "./types"; +import { FORM_INJECTED_SYMBOL, useFormContext } from "../OnyxForm/OnyxForm"; const props = withDefaults(defineProps>(), { modelValue: false, indeterminate: false, - disabled: false, + disabled: FORM_INJECTED_SYMBOL, loading: false, required: false, skeleton: false, @@ -37,6 +38,7 @@ const { requiredMarkerClass, requiredTypeClass } = useRequired(props); const { densityClass } = useDensity(props); const { vCustomValidity, errorMessages } = useCustomValidity({ props, emit }); +const { disabled } = useFormContext(props); const title = computed(() => { return props.hideLabel ? props.label : undefined; @@ -49,7 +51,7 @@ const title = computed(() => { - +