@1024pix/pix-ui 46.10.7 → 46.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/components/pix-radio-button.hbs +11 -1
- package/addon/components/pix-radio-button.js +50 -0
- package/addon/styles/_pix-button-base.scss +2 -0
- package/addon/styles/_pix-radio-button.scss +5 -0
- package/app/stories/pix-checkbox-variant-tile.mdx +1 -1
- package/app/stories/pix-radio-button-variant-tile.mdx +7 -0
- package/app/stories/pix-radio-button-variant-tile.stories.js +35 -0
- package/package.json +1 -1
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
@isDisabled={{this.isDisabled}}
|
|
9
9
|
@inlineLabel={{true}}
|
|
10
10
|
@variant={{@variant}}
|
|
11
|
+
@state={{@state}}
|
|
11
12
|
>
|
|
12
13
|
<:inputElement>
|
|
13
14
|
<input
|
|
14
15
|
type="radio"
|
|
15
16
|
id={{this.id}}
|
|
16
|
-
class=
|
|
17
|
+
class={{this.inputClasses}}
|
|
17
18
|
value={{@value}}
|
|
18
19
|
aria-disabled={{this.isDisabled}}
|
|
20
|
+
aria-describedby={{this.stateId}}
|
|
19
21
|
{{on "click" this.avoidCheckedStateChangeIfIsDisabled}}
|
|
20
22
|
...attributes
|
|
21
23
|
/>
|
|
@@ -24,4 +26,12 @@
|
|
|
24
26
|
{{yield to="label"}}
|
|
25
27
|
</:default>
|
|
26
28
|
</PixLabelWrapped>
|
|
29
|
+
|
|
30
|
+
<span class="screen-reader-only" id={{this.stateId}}>
|
|
31
|
+
{{#if this.hasSuccessState}}
|
|
32
|
+
{{this.stateSuccessMessage}}
|
|
33
|
+
{{else if this.hasErrorState}}
|
|
34
|
+
{{this.stateErrorMessage}}
|
|
35
|
+
{{/if}}
|
|
36
|
+
</span>
|
|
27
37
|
</div>
|
|
@@ -2,14 +2,42 @@ import Component from '@glimmer/component';
|
|
|
2
2
|
import { guidFor } from '@ember/object/internals';
|
|
3
3
|
import { action } from '@ember/object';
|
|
4
4
|
import { warn } from '@ember/debug';
|
|
5
|
+
import { formatMessage } from '../translations';
|
|
5
6
|
|
|
6
7
|
export default class PixRadioButton extends Component {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
|
|
11
|
+
warn(
|
|
12
|
+
'PixRadioButton: @state attribute should be used along with @isDisabled attribute.',
|
|
13
|
+
this.stateWarning,
|
|
14
|
+
{
|
|
15
|
+
id: 'pix-ui.radio-button.state.cant-be-used-without-is-disabled',
|
|
16
|
+
},
|
|
17
|
+
);
|
|
18
|
+
}
|
|
7
19
|
text = 'pix-radio-button';
|
|
8
20
|
|
|
21
|
+
get stateWarning() {
|
|
22
|
+
return Boolean(this.isDisabled) && (!this.hasErrorState || !this.hasSuccessState);
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
get id() {
|
|
10
26
|
return this.args.id || guidFor(this);
|
|
11
27
|
}
|
|
12
28
|
|
|
29
|
+
get stateId() {
|
|
30
|
+
return `${this.id}-state`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get hasSuccessState() {
|
|
34
|
+
return this.args.state === 'success';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get hasErrorState() {
|
|
38
|
+
return this.args.state === 'error';
|
|
39
|
+
}
|
|
40
|
+
|
|
13
41
|
get isDisabled() {
|
|
14
42
|
warn(
|
|
15
43
|
'PixRadioButton: @isDisabled attribute should be a boolean.',
|
|
@@ -22,6 +50,28 @@ export default class PixRadioButton extends Component {
|
|
|
22
50
|
return this.args.isDisabled || this.args.disabled ? 'true' : null;
|
|
23
51
|
}
|
|
24
52
|
|
|
53
|
+
get inputClasses() {
|
|
54
|
+
const classes = ['pix-radio-button__input'];
|
|
55
|
+
|
|
56
|
+
if (this.hasSuccessState || this.hasErrorState) {
|
|
57
|
+
classes.push(`${classes[0]}--state`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return classes.join(' ');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get stateSuccessMessage() {
|
|
64
|
+
return this.formatMessage('state.success');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get stateErrorMessage() {
|
|
68
|
+
return this.formatMessage('state.error');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
formatMessage(message) {
|
|
72
|
+
return formatMessage('fr', `input.${message}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
25
75
|
@action
|
|
26
76
|
avoidCheckedStateChangeIfIsDisabled(event) {
|
|
27
77
|
if (this.args.isDisabled) {
|
|
@@ -25,7 +25,7 @@ Un cursor `not-allowed` est défini sur la checkbox et son label lorsqu'elle est
|
|
|
25
25
|
|
|
26
26
|
#### Succès/Erreur
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Cumulée à la désactivation, une propriété de statut permet de préciser une coloration particulière en cas de "succès" ou d'"erreur".
|
|
29
29
|
|
|
30
30
|
<Story of={ComponentStories.isDisabledIsSuccessVariantTile} height={120} />
|
|
31
31
|
<Story of={ComponentStories.isDisabledIsErrorVariantTile} height={120} />
|
|
@@ -26,6 +26,13 @@ Un cursor `not-allowed` est défini sur le RadioButton et son label lorsqu'il es
|
|
|
26
26
|
<Story of={ComponentStories.isDisabledVariantTile} height={120} />
|
|
27
27
|
<Story of={ComponentStories.checkedIsDisabledVariantTile} height={120} />
|
|
28
28
|
|
|
29
|
+
#### Succès/Erreur
|
|
30
|
+
|
|
31
|
+
Cumulée à la désactivation, une propriété de statut permet de préciser une coloration particulière en cas de "succès" ou d'"erreur".
|
|
32
|
+
|
|
33
|
+
<Story of={ComponentStories.isDisabledIsSuccessVariantTile} height={120} />
|
|
34
|
+
<Story of={ComponentStories.isDisabledIsErrorVariantTile} height={120} />
|
|
35
|
+
|
|
29
36
|
## Usage
|
|
30
37
|
|
|
31
38
|
```html
|
|
@@ -11,6 +11,16 @@ export default {
|
|
|
11
11
|
control: { type: 'select' },
|
|
12
12
|
type: { required: true },
|
|
13
13
|
},
|
|
14
|
+
state: {
|
|
15
|
+
name: 'state',
|
|
16
|
+
description: 'Si `isDisabled` permet de marquer le radiobutton comme correcte ou incorrecte',
|
|
17
|
+
options: ['neutral', 'success', 'error'],
|
|
18
|
+
control: { type: 'select' },
|
|
19
|
+
table: {
|
|
20
|
+
type: { summary: 'string' },
|
|
21
|
+
defaultValue: { summary: 'neutral' },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
14
24
|
...pixRadioButtonStories.argTypes,
|
|
15
25
|
},
|
|
16
26
|
};
|
|
@@ -25,6 +35,8 @@ const VariantTileTemplate = (args) => {
|
|
|
25
35
|
@isDisabled={{this.isDisabled}}
|
|
26
36
|
checked={{this.checked}}
|
|
27
37
|
@variant={{this.variant}}
|
|
38
|
+
@state={{this.state}}
|
|
39
|
+
@size={{this.size}}
|
|
28
40
|
>
|
|
29
41
|
<:label>{{this.label}}</:label>
|
|
30
42
|
</PixRadioButton></div>`,
|
|
@@ -37,6 +49,7 @@ VariantTile.args = {
|
|
|
37
49
|
id: 'proposal',
|
|
38
50
|
label: 'Une réponse',
|
|
39
51
|
variant: 'tile',
|
|
52
|
+
state: 'neutral',
|
|
40
53
|
};
|
|
41
54
|
|
|
42
55
|
export const isDisabledVariantTile = VariantTileTemplate.bind({});
|
|
@@ -45,6 +58,7 @@ isDisabledVariantTile.args = {
|
|
|
45
58
|
label: 'Recevoir la newsletter',
|
|
46
59
|
variant: 'tile',
|
|
47
60
|
isDisabled: true,
|
|
61
|
+
state: 'neutral',
|
|
48
62
|
};
|
|
49
63
|
|
|
50
64
|
export const checkedIsDisabledVariantTile = VariantTileTemplate.bind({});
|
|
@@ -54,4 +68,25 @@ checkedIsDisabledVariantTile.args = {
|
|
|
54
68
|
variant: 'tile',
|
|
55
69
|
isDisabled: true,
|
|
56
70
|
checked: true,
|
|
71
|
+
state: 'neutral',
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const isDisabledIsSuccessVariantTile = VariantTileTemplate.bind({});
|
|
75
|
+
isDisabledIsSuccessVariantTile.args = {
|
|
76
|
+
id: 'accept-newsletter-2',
|
|
77
|
+
label: 'La réponse est correcte',
|
|
78
|
+
variant: 'tile',
|
|
79
|
+
isDisabled: true,
|
|
80
|
+
checked: true,
|
|
81
|
+
state: 'success',
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const isDisabledIsErrorVariantTile = VariantTileTemplate.bind({});
|
|
85
|
+
isDisabledIsErrorVariantTile.args = {
|
|
86
|
+
id: 'accept-newsletter-2',
|
|
87
|
+
label: 'La réponse est fausse',
|
|
88
|
+
variant: 'tile',
|
|
89
|
+
isDisabled: true,
|
|
90
|
+
checked: true,
|
|
91
|
+
state: 'error',
|
|
57
92
|
};
|