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(ui): url step for steps component EBS-1316 #225

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
6 changes: 6 additions & 0 deletions libs/styles/src/lib/scss/components/_steps.scss
MihkelPaloots marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,11 @@
@include cvi-screenreader-text;
}
}

#{$base}__display_desktop {
@include cvi-breakpoint-down(sm) {
display: none;
}
}
}
}
23 changes: 22 additions & 1 deletion libs/ui/src/lib/steps/steps/steps.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ <h1 *ngIf="title" class="cvi-steps__title" dataAttribute="steps_title">{{ title
</cvi-ng-track>
</button>
</li>
<li *ngIf="urlStepTitle"
class="cvi-steps__list-item cvi-steps__display_desktop">
certainlyakey marked this conversation as resolved.
Show resolved Hide resolved
<button class="cvi-steps__list-item-button" style="background-color: white;" (click)="urlStepClicked()">
<cvi-ng-track [layout]="'flex'" [horizontalAlignment]="'justify'" [verticalAlignment]="'center'">
<div class="cvi-steps__list-item-circle-wrapper--desktop">
<cvi-ng-track [gap]="2" [verticalAlignment]="'center'">
<cvi-ng-circle [iconName]="'arrow_a_right'"
[theme]="'light'"
[severity]="'info'"
style="--cvi-circle-border-color: var(--cvi-color-sapphire-blue-13)">
</cvi-ng-circle>
<span class="cvi-steps__list-item-title">{{ urlStepTitle }}</span>
</cvi-ng-track>
</div>
</cvi-ng-track>
</button>
</li>
</ol>
<ng-content></ng-content>
<div *ngIf="this.stepChildren.length > 1 && this.currentStepIndex !== null"
Expand All @@ -56,14 +73,18 @@ <h1 *ngIf="title" class="cvi-steps__title" dataAttribute="steps_title">{{ title
{{ this.stepTitles[this.currentStepIndex - 1] }}
</span>
</button>
<button *ngIf="this.currentStepIndex < this.stepChildren.length - 1"
<button *ngIf="this.currentStepIndex < this.stepChildren.length - 1 || urlStepTitle"
class="cvi-steps__directional-button cvi-steps__directional-button--direction-next"
(click)="stepSelected(this.currentStepIndex + 1)"
[title]="this.stepTitles[this.currentStepIndex + 1]"
[dataAttribute]="'next_step_button_' + this.currentStepIndex">
<span class="cvi-steps__directional-button-label">
{{ this.stepTitles[this.currentStepIndex + 1] }}
</span>
<span *ngIf="urlStepTitle && currentStepIndex === stepTitles.length - 1"
class="cvi-steps__directional-button-label">
{{ (urlStepLabel ? urlStepLabel : '') + urlStepTitle }}
</span>
<cvi-ng-icon [name]="'arrow_a_right'" [svgClass]="'cvi-steps__directional-button-icon'"></cvi-ng-icon>
</button>
</div>
Expand Down
17 changes: 17 additions & 0 deletions libs/ui/src/lib/steps/steps/steps.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,21 @@ describe('StepsComponent', () => {
expect(component.stepChange.emit).toBeCalledTimes(1);
expect(component.stepChange.emit).toBeCalledWith(1);
});

it('should emit url step click when stepSelected is called with stepIndex equal to stepTitles length', () => {
jest.spyOn(component.urlStepClick, 'emit');
component.stepTitles = ['index_0', 'index_1'];
component.stepSelected(2);

expect(component.urlStepClick.emit).toBeCalledTimes(1);
expect(component.urlStepClick.emit).toBeCalledWith();
});

it('should emit url step click when urlStepClicked is called', () => {
jest.spyOn(component.urlStepClick, 'emit');
component.urlStepClicked();

expect(component.urlStepClick.emit).toBeCalledTimes(1);
expect(component.urlStepClick.emit).toBeCalledWith();
});
});
49 changes: 49 additions & 0 deletions libs/ui/src/lib/steps/steps/steps.component.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,52 @@ export const WithStepStatuses = TemplateWithStepStatus.bind({});
WithStepStatuses.args = {
currentStepIndex: 0,
};

const TemplateWithUrlStep: Story = (args) => ({
component: StepsComponent,
props: {
...args,
urlClicked: false,
},
/* template */
template: `
<cvi-ng-notification *ngIf="urlClicked"
[severity]="'success'"
[showCloseButton]="false"
[title]="'URL step clicked'">
URL STEP CLICKED! Clicking url step emits an event <b>urlStepClick</b> that can be used for redirections to other pages and etc.
</cvi-ng-notification>
<cvi-ng-steps [title]="title" [currentStepIndex]="currentStepIndex" [urlStepTitle]="urlStepTitle" (urlStepClick)="urlClicked = true" [urlStepLabel]="urlStepLabel">
<cvi-ng-step>
<cvi-ng-step-panel title="First">
<span>This is just a normal step</span>
</cvi-ng-step-panel>
</cvi-ng-step>
<cvi-ng-step>
<cvi-ng-step-panel title="Second">
<span>This is another normal step, except when you are using mobile. Mobile has arrow button that can be used for redirections to other pages and etc.</span>
</cvi-ng-step-panel>
</cvi-ng-step>
</cvi-ng-steps>
`,
});
export const WithURLStep = TemplateWithUrlStep.bind({});
WithURLStep.args = {
currentStepIndex: 0,
urlStepTitle: 'Navigate to somewhere or do something',
urlStepLabel: 'Next step in your journey: ',
};

export const MobileWithURLStep = TemplateWithUrlStep.bind({});
MobileWithURLStep.args = {
urlStepTitle: 'Navigate to somewhere or do something',
};
MobileWithURLStep.parameters = {
layout: 'fullscreen',
backgrounds: {
default: 'light',
},
viewport: {
defaultViewport: 'iphone12mini',
},
};
14 changes: 14 additions & 0 deletions libs/ui/src/lib/steps/steps/steps.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class StepsComponent
{
@Input() title!: string;

@Input() urlStepTitle?: string;

@Input() urlStepLabel?: string;

/** Internal */
private _currentStepIndex: number | null = null;

Expand All @@ -50,6 +54,8 @@ export class StepsComponent

@Output() stepChange = new EventEmitter<number>();

@Output() urlStepClick = new EventEmitter<any>();

stepStatuses!: ('success' | 'error' | null)[];
stepTitles!: string[];
@Input() currentProgressCSSVar = 0;
Expand Down Expand Up @@ -141,6 +147,10 @@ export class StepsComponent
if (this.currentStepIndex == stepIndex) {
return;
}
if (this.stepTitles.length == stepIndex) {
this.urlStepClicked();
return;
}
this.anyStepSelected = true;
this.currentStepIndex = stepIndex;
this.hideStepsContent();
Expand All @@ -159,4 +169,8 @@ export class StepsComponent
((stepIndex + 1) / this.stepTitles.length) * 100
);
}

urlStepClicked() {
this.urlStepClick.emit();
}
}
Loading