Skip to content

Commit

Permalink
Merge pull request #70 from xsolla/PAYMENTS-18588
Browse files Browse the repository at this point in the history
feat(PAYMENTS-18588): rework select and checkbox component
  • Loading branch information
ekireevxs authored Mar 27, 2024
2 parents ebe6bd5 + 70ebd0a commit 8379984
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 72 deletions.
3 changes: 3 additions & 0 deletions src/assets/icons/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
@use 'src/styles/mixins/typo.mixin' as typo;

psdk-checkbox {
$checkbox-size: 18px;
$checkbox-img-size: 14px;
$checkbox-offset: 1px;
@include typo.psdk-typo;

.checkbox {
position: relative;
display: flex;

.wrapper {
display: flex;
flex-direction: column;
margin-left: 8px;
}

&-dummy {
position: absolute;
top: 0;
left: 0;
display: block;
width: $checkbox-size;
height: $checkbox-size;
border-color: var(--psdk-checkbox-unchecked-bg);
border-radius: 2px;
background: var(--psdk-checkbox-unchecked-bg);

img {
position: absolute;
display: none;
width: $checkbox-img-size;
height: $checkbox-img-size;
inset: $checkbox-offset + 1 $checkbox-offset $checkbox-offset - 1
$checkbox-offset + 1;
}
}
}

input {
z-index: 1;
display: inline-block;
width: $checkbox-size;
height: $checkbox-size;
margin: 0;
border: 1px solid transparent;
background: transparent;
cursor: pointer;
appearance: none;
}

input,
input:checked {
border: 1px solid transparent;
background: transparent;
appearance: none;
}

input:checked + .checkbox-dummy {
border-color: var(--psdk-checkbox-checked-bg);
background: var(--psdk-checkbox-checked-bg);

img {
display: block;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('CheckboxComponent', () => {

window.customElements.define(
WebComponentTagName.CheckboxComponent,
CheckboxComponent
CheckboxComponent,
);

beforeEach(() => {
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('CheckboxComponent', () => {

createComponent();
expect(
document.querySelector(WebComponentTagName.CheckboxComponent)
document.querySelector(WebComponentTagName.CheckboxComponent),
).toBeDefined();
});

Expand All @@ -90,7 +90,7 @@ describe('CheckboxComponent', () => {

const spy = spyOn(
element as unknown as { notifyOnValueChanges(): void },
'notifyOnValueChanges'
'notifyOnValueChanges',
);

setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { XpsBoolean } from '../../../../core/xps-boolean.enum';
import { CheckboxComponentConfig } from './checkbox-component-config.interface';
import check from '../../../../assets/icons/check.svg';

export const getCheckboxComponentTemplate = (
config: CheckboxComponentConfig
config: CheckboxComponentConfig,
): string => {
const isChecked = config.initValue === XpsBoolean.true;
const placeholder = config.placeholder;
const error = config.error;

return `
<label for='${config.name}' class='wrapper'>
<div class='checkbox'>
<input
class='checkbox'
type='checkbox'
id='${config.name}'
name='${config.name}'
${isChecked ? 'checked' : ''}
/>
${placeholder ? `<span class='label'>${placeholder}</span>` : ''}
</label>
<div class='checkbox-dummy'>
${isChecked ? `<img src='${check}' alt='checkbox'>` : ''}
</div>
<div class='wrapper'>
${placeholder ? `<span class='label'>${placeholder}</span>` : ''}
${error ? `<span class='field-error'>${error}</span>` : ''}
</div>
</div>
`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface SelectComponentConfig extends ControlComponentConfig {
readonly?: boolean;
options?: Array<{ label: string; value: string }>;
tooltip?: TextConfigTooltip;
initValue?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum SelectKeys {
enter = 'enter',
space = 'space',
arrowUp = 'arrowup',
arrowDown = 'arrowdown',
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ psdk-select {
.option {
display: flex;

:hover {
:hover, &.active {
background: var(--psdk-select-hover-bg);
color: var(--psdk-select-hover-color);
}

&.focused {
background: var(--psdk-select-focus-bg);
color: var(--psdk-select-focus-color);
}

.option-content {
Expand Down
Loading

0 comments on commit 8379984

Please sign in to comment.