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: in UiQuestion add an optional icon for the Why button #530

Merged
merged 2 commits into from
Sep 12, 2024
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
70 changes: 70 additions & 0 deletions src/components/templates/UiQuestion/UiQuestion.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default {
'data-test': 'why-button',
onClick: events.onClickWhyButton,
},
iconWhyAttrs: { 'data-test': 'info-icon' },
buttonIssueAttrs: {
'data-test': 'issue-button',
onClick: events.onClickIssueButton,
Expand Down Expand Up @@ -558,3 +559,72 @@ export const WithIssueSlot = {
</UiQuestion>`,
}),
};

export const AsSimpleQuestionWithCustomWhyButton = {
render: (args) => ({
components: {
UiQuestion,
UiSimpleQuestion,
},
setup() {
const modelValue = ref('');
return {
...args,
modelValue,
};
},
template: `<UiQuestion
:title="title"
:translation="translation"
:settings="settings"
:heading-title-attrs="headingTitleAttrs"
:button-info-attrs="buttonInfoAttrs"
:icon-info-attrs="iconInfoAttrs"
:button-why-attrs="buttonWhyAttrs"
:icon-why-attrs="iconWhyAttrs"
:button-issue-attrs="buttonIssueAttrs"
:notification-feedback-attrs="notificationFeedbackAttrs"
>
<UiSimpleQuestion
v-model="modelValue"
:items="items"
:legend="title"
/>
</UiQuestion>`,
}),

args: {
title: 'What is your sex?',
translation: { why: 'What should I select?' },
iconWhyAttrs: {
'data-test': 'info-icon',
icon: 'info',
},
items: [
{
value: 'female',
label: 'Female',
icon: 'female',
},
{
value: 'male',
label: 'Male',
icon: 'male',
},
],
},

decorators: [ (story) => ({
components: {
story,
UiControls,
},
template: `<UiControls
:to-next="{path: '/next'}"
:to-back="{path: '/back'}"
class="max-w-195 min-h-135 w-full"
>
<story/>
</UiControls>`,
}) ],
};
13 changes: 13 additions & 0 deletions src/components/templates/UiQuestion/UiQuestion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
buttonIssueAttrs,
settings: defaultProps.settings,
translation: defaultProps.translation,
iconWhyAttrs: defaultProps.iconWhyAttrs,
}"
>
<div
Expand All @@ -98,6 +99,7 @@
settings: defaultProps.settings,
translation: defaultProps.translation,
buttonWhyAttrs,
iconWhyAttrs: defaultProps.iconWhyAttrs,
}"
>
<div
Expand All @@ -108,6 +110,11 @@
v-bind="buttonWhyAttrs"
class="ui-button--small ui-button--text"
>
<UiIcon
v-if="defaultProps.iconWhyAttrs.icon"
v-bind="defaultProps.iconWhyAttrs"
class="ui-button__icon"
/>
{{ defaultProps.translation.why }}
</UiButton>
</div>
Expand Down Expand Up @@ -221,6 +228,10 @@ export interface QuestionProps {
* Use this props to pass attrs for why UiButton
*/
buttonWhyAttrs?: ButtonAttrsProps;
/**
* Use this props to pass attrs for why UiIcon
*/
iconWhyAttrs?: IconAttrsProps;
/**
* Use this props to pass attrs for issue UiButton
*/
Expand Down Expand Up @@ -257,6 +268,7 @@ const props = withDefaults(defineProps<QuestionProps>(), {
buttonInfoAttrs: () => ({}),
iconInfoAttrs: () => ({ icon: 'info' }),
buttonWhyAttrs: () => ({}),
iconWhyAttrs: () => ({ }),
buttonIssueAttrs: () => ({}),
notificationFeedbackAttrs: () => ({ type: 'success' }),
});
Expand Down Expand Up @@ -295,6 +307,7 @@ const defaultProps = computed(() => {
icon,
...props.iconInfoAttrs,
},
iconWhyAttrs: { ...props.iconWhyAttrs },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

icon:info it shouldn't be added by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an icon shouldn't be default because it should be visible only for sex question. The rest of the questions have a rationale button without an icon:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thank_you

Copy link
Contributor

@pspaczek pspaczek Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
iconWhyAttrs: { ...props.iconWhyAttrs },
iconWhyAttrs: {
icon: 'info,
...props.iconWhyAttrs
},

notificationFeedbackAttrs: {
type,
...props.notificationFeedbackAttrs,
Expand Down
Loading