Skip to content
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 PR - make schema work with intl #30

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/editor/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import commentSVG from '@plone/volto/icons/comment.svg';
import { defineMessages } from 'react-intl'; // , defineMessages
import { defineMessages, useIntl } from 'react-intl'; // , defineMessages

import { makeInlineElementPlugin } from '@plone/volto-slate/elementEditor';

Expand All @@ -21,13 +21,19 @@ const messages = defineMessages({
},
});

const SchemaProvider = ({ editSchema, children }) => {
const intl = useIntl();
return children(editSchema({ intl }));
};

export default function install(config) {
const opts = {
title: 'Label',
pluginId: LABEL,
elementType: LABEL,
element: LabelElement,
isInlineElement: true,
schemaProvider: SchemaProvider,
editSchema: LabelEditorSchema,
extensions: [withLabel, withBeforeInsertFragment],
hasValue: (formData) => !!formData,
Expand Down
215 changes: 113 additions & 102 deletions src/editor/schema.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,115 @@
export const LabelEditorSchema = {
title: 'Add label',
fieldsets: [
{
id: 'default',
title: 'Default',
fields: ['label_type', 'label_pointing'],
},
{
id: 'tooltip',
title: 'Tooltip',
fields: [
'tooltip_content',
'tooltip_pointing',
'tooltip_type',
'tooltip_size',
'always_show',
'show_on_hover',
],
},
],
properties: {
label_type: {
title: 'Type of label',
type: 'string',
factory: 'Choice',
choices: [
['simple', 'Simple'],
['medium', 'Medium importance'],
['high', 'High importance'],
['highlight', 'Highlight'],
],
default: 'simple',
description: 'Choose a type or leave the default value (Simple).',
required: true,
noValueOption: false,
},
label_pointing: {
title: 'Label pointing',
type: 'string',
factory: 'Choice',
choices: [
['pointing', 'Up'],
['right pointing', 'Right'],
['left pointing', 'Left'],
['pointing below', 'Down'],
],
description:
'Choose an orientation or leave the default value (No value).',
},
tooltip_content: {
title: 'Tooltip content',
widget: 'slate',
description: 'Enter the text you want to display in the tooltip.',
},
tooltip_pointing: {
title: 'Tooltip position',
type: 'string',
factory: 'Choice',
choices: [
['top center', 'top center'],
['top left', 'top left'],
['top right', 'top right'],
['bottom center', 'bottom center'],
['bottom left', 'bottom left'],
['bottom right', 'bottom right'],
['right center', 'right center'],
['left center', 'left center'],
],
},
tooltip_type: {
title: 'Tooltip type',
type: 'string',
factory: 'Choice',
choices: [
['medium', 'Medium importance'],
['high', 'High importance'],
['highlight', 'Highlight'],
],
default: '',
},
tooltip_size: {
title: 'Tooltip size',
type: 'string',
factory: 'Choice',
choices: [
['wide', 'Wide'],
['extra', 'Extra wide'],
],
default: '',
},
always_show: {
title: 'Always show tooltip',
description: 'Always show the content label tooltip.',
type: 'boolean',
},
show_on_hover: {
title: 'Show tooltip on hover',
description: 'Show the content label tooltip on hover.',
type: 'boolean',
},
import { defineMessages } from 'react-intl';

const messages = defineMessages({
LabelType: {
id: 'LabelType',
defaultMessage: 'Type of label',
},
required: [],
});

export const LabelEditorSchema = ({ intl }) => {
return {
title: 'Add label',
fieldsets: [
{
id: 'default',
title: 'Default',
fields: ['label_type', 'label_pointing'],
},
{
id: 'tooltip',
title: 'Tooltip',
fields: [
'tooltip_content',
'tooltip_pointing',
'tooltip_type',
'tooltip_size',
'always_show',
'show_on_hover',
],
},
],
properties: {
label_type: {
title: intl.formatMessage(messages.LabelType),
type: 'string',
factory: 'Choice',
choices: [
['simple', 'Simple'],
['medium', 'Medium importance'],
['high', 'High importance'],
['highlight', 'Highlight'],
],
default: 'simple',
description: 'Choose a type or leave the default value (Simple).',
required: true,
noValueOption: false,
},
label_pointing: {
title: 'Label pointing',
type: 'string',
factory: 'Choice',
choices: [
['pointing', 'Up'],
['right pointing', 'Right'],
['left pointing', 'Left'],
['pointing below', 'Down'],
],
description:
'Choose an orientation or leave the default value (No value).',
},
tooltip_content: {
title: 'Tooltip content',
widget: 'slate',
description: 'Enter the text you want to display in the tooltip.',
},
tooltip_pointing: {
title: 'Tooltip position',
type: 'string',
factory: 'Choice',
choices: [
['top center', 'top center'],
['top left', 'top left'],
['top right', 'top right'],
['bottom center', 'bottom center'],
['bottom left', 'bottom left'],
['bottom right', 'bottom right'],
['right center', 'right center'],
['left center', 'left center'],
],
},
tooltip_type: {
title: 'Tooltip type',
type: 'string',
factory: 'Choice',
choices: [
['medium', 'Medium importance'],
['high', 'High importance'],
['highlight', 'Highlight'],
],
default: '',
},
tooltip_size: {
title: 'Tooltip size',
type: 'string',
factory: 'Choice',
choices: [
['wide', 'Wide'],
['extra', 'Extra wide'],
],
default: '',
},
always_show: {
title: 'Always show tooltip',
description: 'Always show the content label tooltip.',
type: 'boolean',
},
show_on_hover: {
title: 'Show tooltip on hover',
description: 'Show the content label tooltip on hover.',
type: 'boolean',
},
},
required: [],
};
};