-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create separated CategorizationStepperRenderer and create CategoryIte…
…m type
- Loading branch information
Showing
7 changed files
with
290 additions
and
75 deletions.
There are no files selected for viewing
192 changes: 192 additions & 0 deletions
192
packages/vue-vanilla/src/complex/CategorizationRenderer.vue
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,192 @@ | ||
<template> | ||
<div :class="styles.categorization.root"> | ||
<div :class="styles.categorization.category"> | ||
<template v-for="(item, index) in categories" :key="`tab-${index}`"> | ||
<div @click="selected = index"> | ||
<button | ||
:class="[selected === index ? styles.categorization.selected : '']" | ||
:disabled="!item.isEnabled" | ||
> | ||
<label>{{ item.label }}</label> | ||
</button> | ||
</div> | ||
</template> | ||
</div> | ||
|
||
<div :class="styles.categorization.panel"> | ||
<DispatchRenderer | ||
:schema="layout.schema" | ||
:uischema="currentUischema" | ||
:path="layout.path" | ||
:enabled="layout.enabled" | ||
:renderers="layout.renderers" | ||
:cells="layout.cells" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
import type { | ||
Categorization, | ||
JsonFormsRendererRegistryEntry, | ||
Layout, | ||
UISchemaElement, | ||
} from '@jsonforms/core'; | ||
import { | ||
and, | ||
categorizationHasCategory, | ||
createAjv, | ||
deriveLabelForUISchemaElement, | ||
isEnabled, | ||
isVisible, | ||
rankWith, | ||
isCategorization, | ||
} from '@jsonforms/core'; | ||
import { | ||
DispatchRenderer, | ||
rendererProps, | ||
type RendererProps, | ||
useJsonFormsLayout, | ||
} from '@jsonforms/vue'; | ||
import { type CategoryItem, useTranslator, useVanillaLayout } from '../util'; | ||
const layoutRenderer = defineComponent({ | ||
name: 'CategorizationRenderer', | ||
components: { | ||
DispatchRenderer, | ||
}, | ||
props: { | ||
...rendererProps<Layout>(), | ||
}, | ||
setup(props: RendererProps<Layout>) { | ||
const input = useVanillaLayout(useJsonFormsLayout(props)); | ||
return { | ||
...input, | ||
ajv: createAjv(), | ||
t: useTranslator(), | ||
}; | ||
}, | ||
data() { | ||
return { | ||
selected: 0, | ||
}; | ||
}, | ||
computed: { | ||
currentUischema(): UISchemaElement { | ||
return this.categories[this.selected].element; | ||
}, | ||
categories(): CategoryItem[] { | ||
const { data, path } = this.layout; | ||
return (this.layout.uischema as Categorization).elements | ||
.filter((category) => isVisible(category, data, path, this.ajv)) | ||
.map((category): CategoryItem => { | ||
return { | ||
element: category, | ||
isEnabled: isEnabled(category, data, path, this.ajv), | ||
label: deriveLabelForUISchemaElement(category, this.t), | ||
}; | ||
}); | ||
}, | ||
}, | ||
}); | ||
export default layoutRenderer; | ||
export const entry: JsonFormsRendererRegistryEntry = { | ||
renderer: layoutRenderer, | ||
tester: rankWith(2, and(isCategorization, categorizationHasCategory)), | ||
}; | ||
</script> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +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 CategorizationRenderer } from './Categorization.vue'; | ||
export { default as CategorizationRenderer } from './CategorizationRenderer.vue'; | ||
export { default as CategorizationStepperRenderer } from './CategorizationStepperRenderer.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 categorizationEntry } from './Categorization.vue'; | ||
import { entry as categorizationEntry } from './CategorizationRenderer.vue'; | ||
import { entry as categorizationStepperEntry } from './CategorizationStepperRenderer.vue'; | ||
|
||
export const complexRenderers = [ | ||
objectRendererEntry, | ||
oneOfRendererEntry, | ||
enumArrayRendererEntry, | ||
categorizationEntry, | ||
categorizationStepperEntry, | ||
]; |
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,7 @@ | ||
import { Categorization, Category } from '@jsonforms/core'; | ||
|
||
export type CategoryItem = { | ||
element: Category | Categorization; | ||
isEnabled: boolean; | ||
label?: string; | ||
}; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './options'; | ||
export * from './composition'; | ||
export * from './categorization'; |
Oops, something went wrong.