-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement disabled form tree (#71)
* feat: add cascading disable logic to option groups and options * refactor: add a barrel file for easy importing * feat: implement cascading disabled context for all inputs * chore: include all components in playground * feat: implement form-level disabled * chore: add changeset
- Loading branch information
Showing
25 changed files
with
237 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@formwerk/core': minor | ||
--- | ||
|
||
feat: implement disabled form tree |
24 changes: 24 additions & 0 deletions
24
packages/core/src/helpers/createDisabledContext/createDisabledContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { InjectionKey, MaybeRefOrGetter, Ref, computed, inject, provide, toValue } from 'vue'; | ||
|
||
interface DisabledContext { | ||
isDisabled: Ref<boolean>; | ||
} | ||
|
||
const DisabledContextKey: InjectionKey<DisabledContext> = Symbol('disabledContextKey'); | ||
|
||
/** | ||
* Create a disabled context. | ||
* @param isDisabled - The disabled state. | ||
* @param terminate - Whether to terminate the context and not provide it further. | ||
* @returns The disabled state. | ||
*/ | ||
export function createDisabledContext(isDisabled?: MaybeRefOrGetter<boolean | undefined>) { | ||
const parentContext = inject(DisabledContextKey, null); | ||
const context: DisabledContext = { | ||
isDisabled: computed(() => parentContext?.isDisabled.value || toValue(isDisabled) || false), | ||
}; | ||
|
||
provide(DisabledContextKey, context); | ||
|
||
return context.isDisabled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './createDisabledContext'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.