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

feat(rating-field): add read only #2699

Merged
merged 5 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- "items" (array) (default: []): array of radio_button
- "name" (string) (default: 'rating')
- "helper_id" (string) (default: '')
- "disabled" (boolean) (default: false)
- "invalid" (boolean) (default: false)
- "invalid_icon" (object) default({})
- "star_filled_icon" (object) default({})
Expand All @@ -29,6 +30,7 @@
{% set _items = items|default([]) %}
{% set _name = name|default('rating') %}
{% set _helper_id = helper_id|default('') %}
{% set _disabled = disabled|default(false) %}
{% set _invalid = invalid|default(false) %}
{% set _required = required|default(false) %}
{% set _helper_text = helper_text|default('') %}
Expand Down Expand Up @@ -71,7 +73,8 @@
{%- if _label is not empty %}
<legend
class="ecl-form-label
{{- _invalid ? ' ecl-form-label--invalid' }}"
{{- _invalid ? ' ecl-form-label--invalid' }}
{{- _disabled ? ' ecl-form-label--disabled' -}}"
>
{%- block label _label -%}
{%- if _required and _required_text is not empty -%}
Expand All @@ -84,7 +87,8 @@

{% if _helper_text is not empty %}
<div
class="ecl-help-block"
class="ecl-help-block
{{- _disabled ? ' ecl-help-block--disabled' -}}"
{% if _helper_id is not empty %}
id="{{ _helper_id }}"
{% endif %}
Expand All @@ -106,7 +110,8 @@
{% endif %}

{% if _items is not empty and _items is iterable %}
<div class="ecl-rating-field">
<div class="ecl-rating-field
{{- _disabled ? ' ecl-rating-field--disabled' -}}">
{%- for _item in _items|reverse %}
{% set _item_id = _id ~ '-' ~ _item.value|e('html_attr') %}
<input
Expand All @@ -121,6 +126,9 @@
{% if _required %}
required
{% endif %}
{% if _disabled %}
disabled
{% endif %}
/>
<label
class="ecl-rating-field__label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,24 @@ import dataDefault from '@ecl/specs-component-rating-field/demo/data';
import ratingField from './rating-field.html.twig';
import notes from './README.md';

const itemClone = { ...dataDefault.items[0] };

const getArgs = (data) => {
const args = {
show_label: true,
show_helper: true,
show_error: true,
invalid: data.invalid || false,
disabled: data.disabled || false,
required: data.required,
label: data.label || '',
helper_text: data.helper_text,
invalid_text: data.invalid_text,
invalid: data.invalid || false,
required: data.required,
};

if (!data.binary) {
args.show_item_helper = true;
}

return args;
};

const getArgTypes = (data) => {
const argTypes = getFormControls(data, 'group');

if (!data.binary) {
argTypes.show_item_helper = {
name: 'radio helper text',
type: 'boolean',
description: 'Show radio helper text',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: true },
category: 'Optional',
},
};
}
const argTypes = getFormControls(data, 'element');

return argTypes;
};
Expand All @@ -51,8 +33,6 @@ const prepareData = (data, args) => {
Object.assign(data, args);
correctPaths(data);

const txt = args.show_item_helper ? itemClone.helper_text : '';

if (!args.show_label) {
data.label = '';
}
Expand All @@ -62,16 +42,6 @@ const prepareData = (data, args) => {
if (!args.show_helper) {
data.helper_text = '';
}
if (!data.binary) {
data.items.forEach((item) => {
item.helper_text = txt;
});
}

delete data.show_label;
delete data.show_helper;
delete data.show_error;
delete data.show_item_helper;

return data;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
.ecl-rating-field__input:checked
~ .ecl-rating-field__label
.ecl-rating-field__icon-filled,
& > .ecl-rating-field__label:hover .ecl-rating-field__icon-filled,
&
&:not(.ecl-rating-field--disabled)
> .ecl-rating-field__label:hover
.ecl-rating-field__icon-filled,
&:not(.ecl-rating-field--disabled)
> .ecl-rating-field__label:hover
~ .ecl-rating-field__label
.ecl-rating-field__icon-filled {
Expand All @@ -27,8 +29,10 @@
.ecl-rating-field__input:checked
~ .ecl-rating-field__label
.ecl-rating-field__icon-outline,
& > .ecl-rating-field__label:hover .ecl-rating-field__icon-outline,
&
&:not(.ecl-rating-field--disabled)
> .ecl-rating-field__label:hover
.ecl-rating-field__icon-outline,
&:not(.ecl-rating-field--disabled)
> .ecl-rating-field__label:hover
~ .ecl-rating-field__label
.ecl-rating-field__icon-outline {
Expand All @@ -50,16 +54,22 @@
}

// Focus, active state
.ecl-rating-field__input:focus,
.ecl-rating-field__input:active {
.ecl-rating-field:not(.ecl-rating-field--disabled)
.ecl-rating-field__input:focus,
.ecl-rating-field:not(.ecl-rating-field--disabled)
.ecl-rating-field__input:active {
+ .ecl-rating-field__label {
outline: 2px solid map.get(theme.$color, 'blue');
outline: 2px solid map.get(theme.$color, 'blue-100');
}
}

.ecl-rating-field__label {
cursor: pointer;
margin-right: map.get(theme.$spacing, 'xs');

.ecl-rating-field--disabled & {
cursor: default;
}
}

.ecl-rating-field__icon-filled {
Expand Down
2 changes: 1 addition & 1 deletion src/playground/addons/story-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const getFormControls = (data, type) => {
argTypes.disabled = {
name: 'disabled',
type: 'boolean',
description: `Disabled form ${type}`,
description: `Disabled (read only) form ${type}`,
table: {
type: { summary: 'boolean' },
defaultValue: { summary: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,39 @@ import demoContentDefault from '@ecl/specs-component-rating-field/demo/data';
import template from '@ecl/twig-component-rating-field/rating-field.html.twig';
import { correctSvgPath } from '@ecl/website-utils';

const demoContentSelected = JSON.parse(JSON.stringify(demoContentDefault));
demoContentSelected.label = '';
demoContentSelected.helper_text = '';
demoContentSelected.items[2].checked = true;

export const ratingFieldGroupDefault = template(
correctSvgPath(demoContentDefault)
correctSvgPath({
...demoContentDefault,
id: 'rating-default',
name: 'rating-default',
})
);
export const ratingFieldGroupInvalid = template(
correctSvgPath({
...demoContentDefault,
id: 'rating-invalid',
name: 'rating-invalid',
invalid: true,
})
);
export const ratingFieldGroupOptional = template(
correctSvgPath({
...demoContentDefault,
id: 'rating-optional',
name: 'rating-optional',
required: false,
})
);
export const ratingFieldGroupDisabled = template(
correctSvgPath({
...demoContentSelected,
id: 'rating-disabled',
name: 'rating-disabled',
disabled: true,
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ratingFieldGroupInvalid,
ratingFieldGroupRequired,
ratingFieldGroupOptional,
ratingFieldGroupDisabled,
} from '../demo';

## Default rating field
Expand All @@ -17,7 +18,6 @@ import {
system="ec"
selectedKind="components-forms-rating-field"
selectedStory="default"
showFrame
>
<Html markup={ratingFieldGroupDefault} />
</Playground>
Expand All @@ -29,7 +29,6 @@ import {
selectedKind="components-forms-rating-field"
selectedStory="default"
selectedArgs="invalid:true"
showFrame
>
<Html markup={ratingFieldGroupInvalid} />
</Playground>
Expand All @@ -41,7 +40,17 @@ import {
selectedKind="components-forms-rating-field"
selectedStory="default"
selectedArgs="required:false"
showFrame
>
<Html markup={ratingFieldGroupOptional} />
</Playground>

## Read only rating-field

<Playground
system="ec"
selectedKind="components-forms-rating-field"
selectedStory="default"
selectedArgs="disabled:true"
>
<Html markup={ratingFieldGroupDisabled} />
</Playground>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,39 @@ import demoContentDefault from '@ecl/specs-component-rating-field/demo/data';
import template from '@ecl/twig-component-rating-field/rating-field.html.twig';
import { correctSvgPath } from '@ecl/website-utils';

const demoContentSelected = JSON.parse(JSON.stringify(demoContentDefault));
demoContentSelected.label = '';
demoContentSelected.helper_text = '';
demoContentSelected.items[2].checked = true;

export const ratingFieldGroupDefault = template(
correctSvgPath(demoContentDefault)
correctSvgPath({
...demoContentDefault,
id: 'rating-default',
name: 'rating-default',
})
);
export const ratingFieldGroupInvalid = template(
correctSvgPath({
...demoContentDefault,
id: 'rating-invalid',
name: 'rating-invalid',
invalid: true,
})
);
export const ratingFieldGroupOptional = template(
correctSvgPath({
...demoContentDefault,
id: 'rating-optional',
name: 'rating-optional',
required: false,
})
);
export const ratingFieldGroupDisabled = template(
correctSvgPath({
...demoContentSelected,
id: 'rating-disabled',
name: 'rating-disabled',
disabled: true,
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ratingFieldGroupInvalid,
ratingFieldGroupRequired,
ratingFieldGroupOptional,
ratingFieldGroupDisabled,
} from '../demo';

## Default rating field
Expand All @@ -17,7 +18,6 @@ import {
system="eu"
selectedKind="components-forms-rating-field"
selectedStory="default"
showFrame
>
<Html markup={ratingFieldGroupDefault} />
</Playground>
Expand All @@ -29,7 +29,6 @@ import {
selectedKind="components-forms-rating-field"
selectedStory="default"
selectedArgs="invalid:true"
showFrame
>
<Html markup={ratingFieldGroupInvalid} />
</Playground>
Expand All @@ -41,7 +40,17 @@ import {
selectedKind="components-forms-rating-field"
selectedStory="default"
selectedArgs="required:false"
showFrame
>
<Html markup={ratingFieldGroupOptional} />
</Playground>

## Read only rating-field

<Playground
system="eu"
selectedKind="components-forms-rating-field"
selectedStory="default"
selectedArgs="disabled:true"
>
<Html markup={ratingFieldGroupDisabled} />
</Playground>