Skip to content

Commit

Permalink
More button templates
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jul 3, 2024
1 parent ee30006 commit b174957
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/fontawesome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
faLanguage,
faPen,
faPersonRunning,
faPlus,
faRightToBracket,
faRotate,
faTriangleExclamation,
Expand All @@ -37,6 +38,7 @@ library.add(
faLightbulb,
faPen,
faPersonRunning,
faPlus,
faRightToBracket,
faRotate,
faSquareMinus,
Expand Down
15 changes: 0 additions & 15 deletions src/schema-form/JsonSchemaForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,4 @@ function onError(errors: Error[]) {
::v-deep(input[type="checkbox"], input[type="radio"]) {
@apply mr-2;
}
::v-deep(.btn) {
@apply mink-button;
}
::v-deep(.btn-danger) {
@apply button-danger;
}
::v-deep(.array-item-remove::before) {
content: "";
}
::v-deep(.array-item-move-up::before) {
content: "";
}
::v-deep(.array-item-move-down::before) {
content: "";
}
</style>
10 changes: 3 additions & 7 deletions src/schema-form/theme/AddButton.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<script setup lang="ts">
import ActionButton from "@/components/ActionButton.vue";
defineProps<{
disabled?: boolean;
onClick: () => {};
}>();
</script>

<template>
<!-- eslint-disable -->
<ActionButton :disabled @click="onClick">+</ActionButton>
<ActionButton v-bind="$props">
<icon icon="plus" />
</ActionButton>
</template>
9 changes: 9 additions & 0 deletions src/schema-form/theme/MoveDownButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import ActionButton from "@/components/ActionButton.vue";
</script>

<template>
<ActionButton v-bind="$props">
<icon :icon="['fas', 'angles-down']" />
</ActionButton>
</template>
9 changes: 9 additions & 0 deletions src/schema-form/theme/MoveUpButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import ActionButton from "@/components/ActionButton.vue";
</script>

<template>
<ActionButton v-bind="$props">
<icon :icon="['fas', 'angles-up']" />
</ActionButton>
</template>
9 changes: 9 additions & 0 deletions src/schema-form/theme/RemoveButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import ActionButton from "@/components/ActionButton.vue";
</script>

<template>
<ActionButton v-bind="$props">
<icon :icon="['far', 'trash-can']" />
</ActionButton>
</template>
10 changes: 8 additions & 2 deletions src/schema-form/theme/form-theme.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React from "react";
import { applyPureVueInReact } from "veaury";
import type { ThemeProps } from "@rjsf/core";
import type { FormProps, ThemeProps } from "@rjsf/core";
import type {
FieldProps,
IconButtonProps,
RegistryFieldsType,
} from "@rjsf/utils";
import type { Component } from "vue";
import AddButtonVue from "./AddButton.vue";
import RemoveButtonVue from "./RemoveButton.vue";
import MoveUpButtonVue from "./MoveUpButton.vue";
import MoveDownButtonVue from "./MoveDownButton.vue";

// Rename and retype the Veaury converter to allow specifying return type better.
const toReact = <P = {}>(component: Component) =>
Expand All @@ -30,9 +33,12 @@ class MyField extends React.Component<FieldProps> {

const fields: RegistryFieldsType = { BooleanField: MyField };

const templates = {
const templates: FormProps["templates"] = {
ButtonTemplates: {
AddButton: toReact<IconButtonProps>(AddButtonVue),
RemoveButton: toReact<IconButtonProps>(RemoveButtonVue),
MoveUpButton: toReact<IconButtonProps>(MoveUpButtonVue),
MoveDownButton: toReact<IconButtonProps>(MoveDownButtonVue),
},
};

Expand Down

0 comments on commit b174957

Please sign in to comment.