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

change(cards): Multiple improvements #38

Merged
merged 13 commits into from
Nov 22, 2022
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-listing-block",
"version": "2.0.1",
"version": "2.1.0",
"description": "@eeacms/volto-listing-block: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
16 changes: 8 additions & 8 deletions src/blocks/Listing/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { addStyling } from '@plone/volto/helpers';
// import { addStyling } from '@plone/volto/helpers';
import UniversalCard from '@eeacms/volto-listing-block/components/UniversalCard/UniversalCard';
import { composeSchema } from '@eeacms/volto-listing-block/schema-utils';

import Carousel from './layout-templates/Carousel';
import Gallery from './layout-templates/Gallery';
import Listing from './layout-templates/Listing';
import {
setBasicStylingSchema,
// setBasicStylingSchema,
setCardStylingSchema,
setCardModelSchema,
setItemModelSchema,
Expand Down Expand Up @@ -52,8 +52,8 @@ const applyConfig = (config) => {
title: 'Listing',
template: Listing,
schemaEnhancer: composeSchema(
addStyling,
setBasicStylingSchema,
// addStyling,
// setBasicStylingSchema,
UniversalCard.schemaEnhancer,
),
},
Expand All @@ -63,8 +63,8 @@ const applyConfig = (config) => {
title: 'Carousel',
template: Carousel,
schemaEnhancer: composeSchema(
addStyling,
setBasicStylingSchema,
// addStyling,
// setBasicStylingSchema,
UniversalCard.schemaEnhancer,
Carousel.schemaEnhancer,
),
Expand All @@ -75,8 +75,8 @@ const applyConfig = (config) => {
title: 'Gallery',
template: Gallery,
schemaEnhancer: composeSchema(
addStyling,
setBasicStylingSchema,
// addStyling,
// setBasicStylingSchema,
UniversalCard.schemaEnhancer,
Gallery.schemaEnhancer,
),
Expand Down
3 changes: 3 additions & 0 deletions src/blocks/Listing/item-templates/CardTemplates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const getStyles = (props) => {
if (itemModel.maxDescription) {
res[`max-${itemModel.maxDescription}-lines`] = true;
}
if (itemModel.maxTitle) {
res[`title-max-${itemModel.maxTitle}-lines`] = true;
}
return res;
};

Expand Down
3 changes: 3 additions & 0 deletions src/blocks/Listing/item-templates/ItemTemplates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const getStyles = (props) => {
if (itemModel.maxDescription) {
res[`max-${itemModel.maxDescription}-lines`] = true;
}
if (itemModel.maxTitle) {
res[`title-max-${itemModel.maxTitle}-lines`] = true;
}
return res;
};

Expand Down
3 changes: 3 additions & 0 deletions src/blocks/Listing/item-templates/SearchItemTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const getStyles = (props) => {
if (itemModel.maxDescription) {
res[`max-${itemModel.maxDescription}-lines`] = true;
}
if (itemModel.maxTitle) {
res[`title-max-${itemModel.maxTitle}-lines`] = true;
}
return res;
};

Expand Down
3 changes: 3 additions & 0 deletions src/blocks/Listing/layout-templates/Carousel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import { Button, Icon } from 'semantic-ui-react';
import loadable from '@loadable/component';

import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';

import UniversalCard from '@eeacms/volto-listing-block/components/UniversalCard/UniversalCard';
import ResponsiveContainer from '@eeacms/volto-listing-block/components/ResponsiveContainer';

Expand Down
100 changes: 60 additions & 40 deletions src/blocks/Listing/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ import alignLeftSVG from '@plone/volto/icons/align-left.svg';
import alignCenterSVG from '@plone/volto/icons/align-center.svg';

const ALIGN_INFO_MAP = {
align_left: [alignLeftSVG, 'Left'],
align_center: [alignCenterSVG, 'Center'],
left: [alignLeftSVG, 'Left'],
center: [alignCenterSVG, 'Center'],
};

export const setBasicStylingSchema = (args) => {
const { schema, intl } = args;
schema.properties.styles.schema = {
fieldsets: [
{
id: 'styling',
title: 'Styling',
fields: ['theme', 'inverted', 'rounded'],
},
],
properties: {
theme: {
title: intl.formatMessage(messages.Theme),
description: intl.formatMessage(messages.ThemeHelp),
choices: [
['', intl.formatMessage(messages.ThemeDefault)],
['primary', intl.formatMessage(messages.ThemePrimary)],
['secondary', intl.formatMessage(messages.ThemeSecondary)],
['tertiary', intl.formatMessage(messages.ThemeTertiary)],
],
},
inverted: {
title: intl.formatMessage(messages.Inverted),
description: intl.formatMessage(messages.InvertedHelp),
type: 'boolean',
},
rounded: {
title: intl.formatMessage(messages.Rounded),
description: intl.formatMessage(messages.RoundedHelp),
type: 'boolean',
},
},
required: [],
};
// export const setBasicStylingSchema = (args) => {
// const { schema, intl } = args;
// schema.properties.styles.schema = {
// fieldsets: [
// {
// id: 'styling',
// title: 'Styling',
// fields: ['theme', 'inverted', 'rounded'],
// },
// ],
// properties: {
// theme: {
// title: intl.formatMessage(messages.Theme),
// description: intl.formatMessage(messages.ThemeHelp),
// choices: [
// ['', intl.formatMessage(messages.ThemeDefault)],
// ['primary', intl.formatMessage(messages.ThemePrimary)],
// ['secondary', intl.formatMessage(messages.ThemeSecondary)],
// ['tertiary', intl.formatMessage(messages.ThemeTertiary)],
// ],
// },
// inverted: {
// title: intl.formatMessage(messages.Inverted),
// description: intl.formatMessage(messages.InvertedHelp),
// type: 'boolean',
// },
// rounded: {
// title: intl.formatMessage(messages.Rounded),
// description: intl.formatMessage(messages.RoundedHelp),
// type: 'boolean',
// },
// },
// required: [],
// };

return schema;
};
// return schema;
// };

const CallToActionSchema = ({ formData }) => {
return {
Expand Down Expand Up @@ -98,6 +98,7 @@ export const setCardModelSchema = (args) => {
const itemModelSchema = schema.properties.itemModel.schema;
itemModelSchema.fieldsets[0].fields = [
...itemModelSchema.fieldsets[0].fields,
'maxTitle',
'hasDate',
'hasDescription',
...(formData?.itemModel?.hasDescription ? ['maxDescription'] : []),
Expand All @@ -116,6 +117,15 @@ export const setCardModelSchema = (args) => {
title: 'Description',
type: 'boolean',
},
maxTitle: {
title: 'Title max lines',
description:
"Limit title to a maximum number of lines by adding trailing '...'",
type: 'number',
default: 2,
minimum: 0,
maximum: 5,
},
maxDescription: {
title: 'Description max lines',
description:
Expand Down Expand Up @@ -153,6 +163,7 @@ export const setItemModelSchema = (args) => {

itemModelSchema.fieldsets[0].fields = [
...itemModelSchema.fieldsets[0].fields,
'maxTitle',
'hasDate',
'hasDescription',
'maxDescription',
Expand All @@ -175,6 +186,15 @@ export const setItemModelSchema = (args) => {
type: 'boolean',
default: true,
},
maxTitle: {
title: 'Title max lines',
description:
"Limit title to a maximum number of lines by adding trailing '...'",
type: 'number',
default: 2,
minimum: 0,
maximum: 5,
},
maxDescription: {
title: 'Description max lines',
description:
Expand Down Expand Up @@ -214,7 +234,7 @@ export const setCardStylingSchema = ({ schema, intl }) => {
const itemModelSchema = schema.properties.itemModel;
const styleSchema = itemModelSchema.schema.properties.styles.schema;
const fieldset = styleSchema.fieldsets.find(({ id }) => id === 'default');
fieldset.fields.push('theme', 'inverted', 'rounded', 'text_align');
fieldset.fields.push('theme', 'inverted', 'rounded', 'text');
styleSchema.properties = {
...styleSchema.properties,
theme: {
Expand All @@ -237,7 +257,7 @@ export const setCardStylingSchema = ({ schema, intl }) => {
description: intl.formatMessage(messages.RoundedHelp),
type: 'boolean',
},
text_align: {
text: {
title: 'Text align',
widget: 'style_text_align',
actions: Object.keys(ALIGN_INFO_MAP),
Expand Down
8 changes: 4 additions & 4 deletions src/blocks/Teaser/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { composeSchema } from '@eeacms/volto-listing-block/schema-utils';
import { addStyling } from '@plone/volto/helpers';
// import { addStyling } from '@plone/volto/helpers';

import TeaserCardTemplate from './Card';
import { adjustTeaserSchema } from './schema';
import UniversalCard from '@eeacms/volto-listing-block/components/UniversalCard/UniversalCard';
import { setBasicStylingSchema } from '../Listing/schema';
// import { setBasicStylingSchema } from '../Listing/schema';

export default (config) => {
if (config.blocks.blocksConfig.teaser) {
config.blocks.blocksConfig.teaser.schemaEnhancer = composeSchema(
config.blocks.blocksConfig.teaser.schemaEnhancer,
addStyling,
setBasicStylingSchema,
// addStyling,
// setBasicStylingSchema,
);

config.blocks.blocksConfig.teaser.variations = [
Expand Down
16 changes: 8 additions & 8 deletions src/components/UniversalCard/fragments/CardMeta.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ const CardMeta = (props) => {
const locale = config.settings.dateLocale || 'en-gb';
const showDate = itemModel.hasDate !== false && EffectiveDate !== 'None';
const showMeta = !!(head_title || (itemModel?.hasMetaType && item['@type']));
const show = showDate || showMeta;
// const show = showDate || showMeta;

// TODO: <EEAFormattedDate data={EffectiveDate} />

return show ? (
return (
<UiCard.Meta>
{showMeta && (
<span className="text-left">{head_title || item['Type']}</span>
)}
{showDate && (
<span className="text-right date">
{formatDate({

<span className="text-right date">
{showDate &&
formatDate({
date: EffectiveDate,
format: {
year: 'numeric',
Expand All @@ -29,10 +30,9 @@ const CardMeta = (props) => {
},
locale: locale,
})}
</span>
)}
</span>
</UiCard.Meta>
) : null;
);
};

export default CardMeta;
Loading