-
Notifications
You must be signed in to change notification settings - Fork 391
Radio Group Renderer for Vue Vanilla (WIP) #2292
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
Draft
davewwww
wants to merge
1
commit into
eclipsesource:master
Choose a base branch
from
davewwww:feat/radio-group-renderer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/vue-vanilla/src/complex/RadioGroupEnumControlRenderer.vue
This file contains hidden or 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,58 @@ | ||
<template> | ||
<control-wrapper | ||
v-bind="controlWrapper" | ||
:styles="styles" | ||
:is-focused="isFocused" | ||
:applied-options="appliedOptions" | ||
> | ||
<RadioGroupControl | ||
:id="control.id" | ||
:options="control.options" | ||
:enabled="control.enabled" | ||
:required="control.required" | ||
:styles="styles" | ||
:on-change="onChange" | ||
/> | ||
</control-wrapper> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
import { | ||
and, | ||
type ControlElement, | ||
isEnumControl, | ||
type JsonFormsRendererRegistryEntry, | ||
optionIs, | ||
rankWith, | ||
} from '@jsonforms/core'; | ||
import { | ||
rendererProps, | ||
type RendererProps, | ||
useJsonFormsEnumControl, | ||
} from '@jsonforms/vue'; | ||
import { ControlWrapper } from '../controls'; | ||
import { useVanillaControl } from '../util'; | ||
import RadioGroupControl from './components/RadioGroupControl.vue'; | ||
|
||
const controlRenderer = defineComponent({ | ||
name: 'RadioGroupControlRenderer', | ||
components: { | ||
RadioGroupControl, | ||
ControlWrapper, | ||
}, | ||
props: { | ||
...rendererProps<ControlElement>(), | ||
}, | ||
setup(props: RendererProps<ControlElement>) { | ||
return useVanillaControl(useJsonFormsEnumControl(props)); | ||
}, | ||
}); | ||
|
||
export default controlRenderer; | ||
|
||
export const entry: JsonFormsRendererRegistryEntry = { | ||
renderer: controlRenderer, | ||
tester: rankWith(20, and(isEnumControl, optionIs('format', 'radio'))), | ||
}; | ||
</script> |
59 changes: 59 additions & 0 deletions
59
packages/vue-vanilla/src/complex/RadioGroupOneOfControlRenderer.vue
This file contains hidden or 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,59 @@ | ||||||
<template> | ||||||
<control-wrapper | ||||||
v-bind="controlWrapper" | ||||||
:styles="styles" | ||||||
:is-focused="isFocused" | ||||||
:applied-options="appliedOptions" | ||||||
> | ||||||
<RadioGroupControl | ||||||
:id="control.id" | ||||||
:options="control.options" | ||||||
:enabled="control.enabled" | ||||||
:required="control.required" | ||||||
:styles="styles" | ||||||
:on-change="onChange" | ||||||
/> | ||||||
</control-wrapper> | ||||||
</template> | ||||||
|
||||||
|
||||||
<script lang="ts"> | ||||||
import { defineComponent } from 'vue'; | ||||||
import { | ||||||
and, | ||||||
type ControlElement, | ||||||
isOneOfEnumControl, | ||||||
type JsonFormsRendererRegistryEntry, | ||||||
optionIs, | ||||||
rankWith, | ||||||
} from '@jsonforms/core'; | ||||||
import { | ||||||
rendererProps, | ||||||
type RendererProps, | ||||||
useJsonFormsOneOfEnumControl, | ||||||
} from '@jsonforms/vue'; | ||||||
import { ControlWrapper } from '../controls'; | ||||||
import { useVanillaControl } from '../util'; | ||||||
import RadioGroupControl from './components/RadioGroupControl.vue'; | ||||||
|
||||||
const controlRenderer = defineComponent({ | ||||||
name: 'RadioGroupControlRenderer', | ||||||
components: { | ||||||
RadioGroupControl, | ||||||
ControlWrapper, | ||||||
}, | ||||||
props: { | ||||||
...rendererProps<ControlElement>(), | ||||||
}, | ||||||
setup(props: RendererProps<ControlElement>) { | ||||||
return useVanillaControl(useJsonFormsOneOfEnumControl(props)); | ||||||
}, | ||||||
}); | ||||||
|
||||||
export default controlRenderer; | ||||||
|
||||||
export const entry: JsonFormsRendererRegistryEntry = { | ||||||
renderer: controlRenderer, | ||||||
tester: rankWith(20, and(isOneOfEnumControl, optionIs('format', 'radio'))), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: rank 20 seems unnecessarily high considering standard renderers usually use values between 1 and 5. E.g. the plain enum renderer uses 2.
Suggested change
|
||||||
}; | ||||||
</script> |
62 changes: 62 additions & 0 deletions
62
packages/vue-vanilla/src/complex/components/RadioGroupControl.vue
This file contains hidden or 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,62 @@ | ||
<template> | ||
<div :id="id + '-input'" :class="styles.control.radioGroup"> | ||
<div | ||
v-for="option in options" | ||
:key="option.value" | ||
:class="styles.control.radioGroupItem" | ||
> | ||
<input | ||
:id="id + '.' + option.value" | ||
type="radio" | ||
:name="id" | ||
:value="option.value" | ||
:disabled="!enabled" | ||
:required="required" | ||
@change="onChange" | ||
/> | ||
|
||
<label | ||
:for="id + '.' + option.value" | ||
:class="styles.control.radioGroupItemLabel" | ||
>{{ option.label }}</label | ||
> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, PropType } from 'vue'; | ||
import { Styles } from '../../styles'; | ||
|
||
export default defineComponent({ | ||
name: 'RadioGroupControl', | ||
props: { | ||
id: { | ||
required: true, | ||
type: String, | ||
}, | ||
enabled: { | ||
required: false as const, | ||
type: Boolean, | ||
default: true, | ||
}, | ||
required: { | ||
required: false as const, | ||
type: Boolean, | ||
default: false, | ||
}, | ||
styles: { | ||
required: true, | ||
type: Object as PropType<Styles>, | ||
}, | ||
options: { | ||
required: true, | ||
type: Array, | ||
}, | ||
onChange: { | ||
required: true, | ||
type: Function, | ||
}, | ||
}, | ||
}); | ||
</script> |
This file contains hidden or 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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
export { default as ObjectRenderer } from './ObjectRenderer.vue'; | ||
export { default as OneOfRenderer } from './OneOfRenderer.vue'; | ||
export { default as EnumArrayRenderer } from './EnumArrayRenderer.vue'; | ||
export { default as RadioGroupEnumControlRenderer } from './RadioGroupEnumControlRenderer.vue'; | ||
export { default as RadioGroupControlRenderer } from './RadioGroupOneOfControlRenderer.vue'; | ||
|
||
import { entry as objectRendererEntry } from './ObjectRenderer.vue'; | ||
import { entry as oneOfRendererEntry } from './OneOfRenderer.vue'; | ||
import { entry as enumArrayRendererEntry } from './EnumArrayRenderer.vue'; | ||
import { entry as radioGroupEnumControlEntry } from './RadioGroupEnumControlRenderer.vue'; | ||
import { entry as radioGroupOneOfControlEntry } from './RadioGroupOneOfControlRenderer.vue'; | ||
|
||
export const complexRenderers = [ | ||
objectRendererEntry, | ||
oneOfRendererEntry, | ||
enumArrayRendererEntry, | ||
radioGroupEnumControlEntry, | ||
radioGroupOneOfControlEntry, | ||
]; |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: rank
20
seems unnecessarily high considering standard renderers usually use values between 1 and 5. E.g. the plain enum renderer uses2
.