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: develop pin-input #91

Closed
wants to merge 9 commits into from
Prev Previous commit
fix: resolve issues in MR
hossein-nas committed Oct 30, 2024

Verified

This commit was signed with the committer’s verified signature.
CristhianF7 Cristhian Fernández
commit f60343364ea8ec8118a0f68cb6c11cada816c5b0
103 changes: 17 additions & 86 deletions src/pin-input-cell/events.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BaseEvent } from '../utils';
import {
PIN_INPUT_CELL_ARROW_KEY_PRESSED_TYPE,
PIN_INPUT_CELL_CLEARED_ALL_TYPE,
@@ -7,116 +8,46 @@ import {
} from './constants';
import { ValueChangedEventParams } from './types';

export class PinInputCellFilled extends Event {
public message: string;
public details: ValueChangedEventParams;

constructor(
message: string,
details: ValueChangedEventParams,
eventInitDict: EventInit = {},
) {
const _eventInitDict = {
bubbles: true,
composed: false,
...eventInitDict,
};
const type = PIN_INPUT_CELL_FILLED_TYPE;
super(type, _eventInitDict);

this.details = details;
this.message = message;
export class CellFilled extends BaseEvent<ValueChangedEventParams> {
static type = PIN_INPUT_CELL_FILLED_TYPE;
constructor(details: ValueChangedEventParams){
super(CellFilled.type, {details})
}
}

export class PinInputCellCleared extends Event {
public message: string;
public details: ValueChangedEventParams;

export class CellCleared extends BaseEvent<ValueChangedEventParams> {
static type = PIN_INPUT_CELL_CLEARED_TYPE;
constructor(
message: string,
details: ValueChangedEventParams,
eventInitDict: EventInit = {},
) {
const _eventInitDict = {
bubbles: true,
composed: false,
...eventInitDict,
};

const type = PIN_INPUT_CELL_CLEARED_TYPE;
super(type, _eventInitDict);

this.details = details;
this.message = message;
super(CellCleared.type, {details});
}
}

export class PinInputCellClearedAll extends Event {
public message: string;
public details: ValueChangedEventParams;

export class CellClearedAll extends BaseEvent<ValueChangedEventParams> {
static type = PIN_INPUT_CELL_CLEARED_ALL_TYPE;
constructor(
message: string,
details: ValueChangedEventParams,
eventInitDict: EventInit = {},
) {
const _eventInitDict = {
bubbles: true,
composed: false,
...eventInitDict,
};

const type = PIN_INPUT_CELL_CLEARED_ALL_TYPE;
super(type, _eventInitDict);

this.details = details;
this.message = message;
super(CellClearedAll.type, {details});
}
}

export class PinInputCellArrowKeyPressed<T = 'left' | 'right'> extends Event {
public message: string;
public details: ValueChangedEventParams<T>;

export class CellArrowKeyPressed<T = 'left' | 'right'> extends BaseEvent<ValueChangedEventParams<T>> {
static type = PIN_INPUT_CELL_ARROW_KEY_PRESSED_TYPE;
constructor(
message: string,
details: ValueChangedEventParams<T>,
eventInitDict: EventInit = {},
) {
const _eventInitDict = {
bubbles: true,
composed: false,
...eventInitDict,
};

const type = PIN_INPUT_CELL_ARROW_KEY_PRESSED_TYPE;
super(type, _eventInitDict);

this.details = details;
this.message = message;
super(CellArrowKeyPressed.type, {details});
}
}

export class PinInputCellOverflowValue extends Event {
public message: string;
public details: ValueChangedEventParams;

export class CellOverflowValue extends BaseEvent<ValueChangedEventParams> {
static type = PIN_INPUT_CELL_OVERFLOW_VALUE_TYPE;
constructor(
message: string,
details: ValueChangedEventParams,
eventInitDict: EventInit = {},
) {
const _eventInitDict = {
bubbles: true,
composed: false,
...eventInitDict,
};

const type = PIN_INPUT_CELL_OVERFLOW_VALUE_TYPE;
super(type, _eventInitDict);

this.details = details;
this.message = message;
super(CellOverflowValue.type, {details});
}
}
23 changes: 10 additions & 13 deletions src/pin-input-cell/pin-input-cell.ts
Copy link
Collaborator

Choose a reason for hiding this comment

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

To enhance simplicity and readability, consider moving most of the logic to the pin-input component. For instance, handling keyboard events could be consolidated within the pin-input element, rather than having both components engaged in event handling

Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@ import {
persianToEnglish,
} from './util';
import {
PinInputCellArrowKeyPressed,
PinInputCellCleared,
PinInputCellClearedAll,
PinInputCellFilled,
PinInputCellOverflowValue,
CellArrowKeyPressed,
CellCleared,
CellClearedAll,
CellFilled,
CellOverflowValue,
} from './events';

export class PinInputCell extends LitElement {
@@ -56,7 +56,7 @@ export class PinInputCell extends LitElement {

private async emitValueChanged() {
await this.updateComplete;
const event = new PinInputCellFilled('PinInputCell filled', {
const event = new CellFilled({
cell: this,
index: this.index,
value: this.value,
@@ -67,7 +67,7 @@ export class PinInputCell extends LitElement {

private async emitValueCleared() {
await this.updateComplete;
const event = new PinInputCellCleared('PinInputCell cleared', {
const event = new CellCleared({
cell: this,
index: this.index,
value: this.value,
@@ -78,7 +78,7 @@ export class PinInputCell extends LitElement {

private async emitDeletionWithMetaKeys() {
await this.updateComplete;
const event = new PinInputCellClearedAll('PinInputCell cleared all', {
const event = new CellClearedAll({
cell: this,
index: this.index,
value: this.value,
@@ -90,8 +90,7 @@ export class PinInputCell extends LitElement {
private async emitArrowKeyPressed(key: 'ArrowLeft' | 'ArrowRight') {
await this.updateComplete;

const event = new PinInputCellArrowKeyPressed<'left' | 'right'>(
'PinInputCell arrow key pressed',
const event = new CellArrowKeyPressed(
{
cell: this,
index: this.index,
@@ -104,9 +103,7 @@ export class PinInputCell extends LitElement {

private async emitOverflowedValue(value: string) {
await this.updateComplete;
const event = new PinInputCellOverflowValue(
'PinInputCell Overflowed value',
{
const event = new CellOverflowValue({
cell: this,
index: this.index,
value: value,
2 changes: 1 addition & 1 deletion src/pin-input/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PIN_INPUT_FILLED_TYPE = 'input-filled';
export const PIN_INPUT_FILLED_TYPE = 'filled';
25 changes: 5 additions & 20 deletions src/pin-input/events.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
import { BaseEvent } from '../utils';
import { PIN_INPUT_FILLED_TYPE } from './constants';
import { InputFilledEventParams } from './types';

export class PinInputFilled extends Event {
public message: string;
public details: InputFilledEventParams;

constructor(
message: string,
details: InputFilledEventParams,
eventInitDict: EventInit = {},
) {
const _eventInitDict = {
bubbles: true,
composed: false,
...eventInitDict,
};

const type = PIN_INPUT_FILLED_TYPE;
super(type, _eventInitDict);

this.details = details;
this.message = message;
export class Filled extends BaseEvent<InputFilledEventParams> {
static type = PIN_INPUT_FILLED_TYPE;
constructor(details: InputFilledEventParams){
super(Filled.type, {details})
}
}
4 changes: 2 additions & 2 deletions src/pin-input/pin-input.stories.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ const Template: Story<ArgTypes> = (/*{}: ArgTypes*/) => html`
<tap-pin-input
title="عنوان"
description="توضیحات"
@input-filled=${(e: Error) => console.log(e)}
@filled=${(e: Error) => console.log(e)}
></tap-pin-input>
`;

@@ -41,7 +41,7 @@ const TemplateWithForm: Story<ArgTypes> = (/*{}: ArgTypes*/) => html`
<tap-pin-input
title="عنوان"
description="توضیحات"
@input-filled=${(e: Error) => console.log(e)}
@filled=${(e: Error) => console.log(e)}
></tap-pin-input>
<button type="submit">Submit</button>
</form>
Loading