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

refactor: introduce kebab events #526

Merged
merged 30 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2706676
refactor: test possible kebab events implementation with checkbox com…
acstll Aug 18, 2021
5ad76b3
style: format 😑
acstll Aug 18, 2021
d65d169
refactor: kebab events implementation with collapsible component
ChrisPaj Aug 23, 2021
a108655
refactor: kebab events implementation with date-picker component
ChrisPaj Aug 23, 2021
da32ba6
style: format collapsible
ChrisPaj Aug 23, 2021
7416209
refactor: kebab events implementation with input component
ChrisPaj Aug 24, 2021
e23b792
refactor: adapt emitEvent() - 3rd argument (event payload) is now opt…
ChrisPaj Aug 24, 2021
c12868b
refactor: kebab events implementation with menu-flyout component w/o …
ChrisPaj Aug 24, 2021
4b1378f
refactor: kebab events implementation with menu-flyout-list component
ChrisPaj Aug 24, 2021
eea0c29
refactor: kebab events implementation with modal component w/o storybook
ChrisPaj Aug 24, 2021
0d56e83
refactor: kebab events implementation with radio-button component w/o…
ChrisPaj Aug 25, 2021
57fd8ac
refactor: kebab events implementation with slider component w/o story…
ChrisPaj Aug 25, 2021
6ff5970
refactor: kebab events implementation with switch component w/o story…
ChrisPaj Aug 25, 2021
1ca4bf9
refactor: kebab events implementation with tag component w/o storybook
ChrisPaj Aug 25, 2021
6606e0e
refactor: kebab events implementation with text-field component w/o s…
ChrisPaj Aug 25, 2021
b54f2e6
refactor: kebab events implementation with textarea component w/o sto…
ChrisPaj Aug 25, 2021
15bd064
Merge branch 'main' into refactor/kebab-events
ChrisPaj Aug 25, 2021
9206fbd
refactor: kebab events implementation with rating-stars component w/o…
ChrisPaj Aug 25, 2021
f810ddc
refactor: kebab events implementation with pagination component w/o s…
ChrisPaj Aug 25, 2021
3f32208
refactor: kebab events implementation with data-grid component w/o st…
ChrisPaj Aug 25, 2021
f38a9c7
refactor: kebab events implementation with dropdown component w/o sto…
ChrisPaj Aug 25, 2021
7c86a65
refactor: use kebab for internal @Listen
acstll Aug 27, 2021
9be51cd
Merge branch 'main' into refactor/kebab-events
ChrisPaj Aug 27, 2021
5dbf1ff
fix: adapt visual tests
ChrisPaj Aug 27, 2021
0457132
fix(angular): add post-processing to angular proxies for fixing kebab…
oddcelot Aug 30, 2021
d5a9595
chore: add angular proxy processing to build pipeline
oddcelot Aug 30, 2021
76bfdb9
Merge branch 'main' into refactor/kebab-events
nowseemee Aug 30, 2021
71480d7
refactor: remove dead code (comments)
ChrisPaj Aug 30, 2021
46f0347
feat: show new events in stories
ChrisPaj Aug 31, 2021
f99cba6
refactor: remove unnecessary events from vue templates
ChrisPaj Aug 31, 2021
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
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:

- name: Build Angular Proxy
run: |
yarn workspace @telekom/scale-components process-angular-proxies
yarn workspace @telekom/scale-components-angular build

- name: Build React Proxy
Expand Down Expand Up @@ -123,6 +124,7 @@ jobs:

- name: Build Angular Proxy
run: |
yarn workspace @telekom/scale-components process-angular-proxies
yarn workspace @telekom/scale-components-angular-neutral build

- name: Build React Proxy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ElementRef, HostListener } from '@angular/core';
import { Directive, ElementRef, HostListener } from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';

@Directive({})
export class ValueAccessor implements ControlValueAccessor {

private onChange: (value: any) => void = () => {/**/};
Expand Down
5 changes: 3 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
"format": "prettier --write \"*.ts\" \"src/**/*.{html,tsx,ts,css,json}\" \"!src/**/*.d.ts\"",
"lint:fix": "yarn lint:style --fix",
"lint": "tslint -c tslint.json -p . \"src/**/*.{tsx,ts,css,json}\" \"!src/**/*.d.ts\"",
"generate": "node ./scripts/generate-icons.js"
"generate": "node ./scripts/generate-icons.js",
"process-angular-proxies": "node ./scripts/process-angular-proxies.js"
},
"devDependencies": {
"@babel/core": "7.10.2",
"@babel/plugin-syntax-jsx": "7.10.1",
"@babel/plugin-transform-react-jsx": "7.10.1",
"@nowseemee/vue-output-target": "0.0.4",
"@stencil/angular-output-target": "^0.0.5",
"@stencil/angular-output-target": "^0.0.7",
"@stencil/postcss": "^2.0.0",
"@stencil/react-output-target": "^0.0.9",
"@types/classnames": "2.2.8",
Expand Down
15 changes: 15 additions & 0 deletions packages/components/scripts/process-angular-proxies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require('fs');
const angularProxiesFile = '../components-angular/src/directives/proxies.ts';

fs.readFile(angularProxiesFile, 'utf8', (err, data) => {
if (err) return console.log(err);

// regex matches the kebab case event name
const withEscapedKeys = data.replace(/(\w)+(-(\w)+)+!:/g, (match) => {
return `"${match.split('!:')[0]}"!:`;
});

fs.writeFile(angularProxiesFile, withEscapedKeys, 'utf8', (err) => {
if (err) return console.log(err);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Accordion {
/**
* Handle `dependent`
*/
@Listen('scaleExpand')
@Listen('scale-expand')
collapsibleHandler(event: CustomEvent) {
event.stopPropagation();
const { expanded } = event.detail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CheckboxGroup {

@State() groupStatus: CheckboxState[] = [];

@Listen('scaleChange')
@Listen('scale-change')
scaleChangeHandler() {
this.createNewState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ describe('Checkbox', () => {

it('should emit on change', async () => {
const changeSpy = jest.fn();
page.doc.addEventListener('scaleChange', changeSpy);
const changeSpyLegacy = jest.fn();
page.doc.addEventListener('scale-change', changeSpy);
page.doc.addEventListener('scaleChange', changeSpyLegacy);
const element = page.root.querySelector('input');
element.dispatchEvent(new Event('change'));
await page.waitForChanges();
expect(changeSpy).toHaveBeenCalled();
expect(changeSpyLegacy).toHaveBeenCalled();
});

it('should handle inputId with value null', async () => {
Expand Down
9 changes: 6 additions & 3 deletions packages/components/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Prop,
} from '@stencil/core';
import classNames from 'classnames';
import { emitEvent } from '../../utils/utils';

let i = 0;

Expand Down Expand Up @@ -49,8 +50,11 @@ export class Checkbox {
@Prop() inputId?: string;
/** (optional) Injected CSS styles */
@Prop() styles?: string;

/** Emitted when the value has changed. */
@Event() scaleChange!: EventEmitter;
@Event({ eventName: 'scale-change' }) scaleChange: EventEmitter;
/** @deprecated in v3 in favor of kebab-case event names */
@Event({ eventName: 'scaleChange' }) scaleChangeLegacy: EventEmitter;

componentWillLoad() {
if (this.inputId == null) {
Expand Down Expand Up @@ -104,8 +108,7 @@ export class Checkbox {
this.indeterminate = false;
}
this.checked = e.target.checked;
// bubble event through the shadow dom
this.scaleChange.emit({ value: this.checked });
emitEvent(this, 'scaleChange', { value: this.checked });
}}
value={this.value}
checked={this.checked}
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/components/checkbox/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@

## Events

| Event | Description | Type |
| ------------- | ----------------------------------- | ------------------ |
| `scaleChange` | Emitted when the value has changed. | `CustomEvent<any>` |
| Event | Description | Type |
| -------------- | -------------------------------------------------------------------------------------------------- | ------------------ |
| `scale-change` | Emitted when the value has changed. | `CustomEvent<any>` |
| `scaleChange` | <span style="color:red">**[DEPRECATED]**</span> in v3 in favor of kebab-case event names<br/><br/> | `CustomEvent<any>` |


## Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ describe('TextField', () => {
});
it('should emit on click', async () => {
const clickSpy = jest.fn();
page.doc.addEventListener('scaleExpand', clickSpy);
const clickSpyLegacy = jest.fn();
page.doc.addEventListener('scale-expand', clickSpy);
page.doc.addEventListener('scaleExpand', clickSpyLegacy);
const buttonElement = page.root.shadowRoot.querySelector('button');
buttonElement.click();
await page.waitForChanges();
expect(clickSpy).toHaveBeenCalled();
expect(clickSpyLegacy).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EventEmitter,
} from '@stencil/core';
import classNames from 'classnames';
import { emitEvent } from '../../utils/utils';

export interface CollapsibleEventDetail {
expanded: boolean;
Expand Down Expand Up @@ -46,7 +47,11 @@ export class Collapsible {
@Prop() styles?: string;

/** Emitted so parent <scale-accordion> knows about it */
@Event() scaleExpand: EventEmitter<CollapsibleEventDetail>;
@Event({ eventName: 'scale-expand' })
scaleExpand: EventEmitter<CollapsibleEventDetail>;
/** @deprecated in v3 in favor of kebab-case event names */
@Event({ eventName: 'scaleExpand' })
scaleExpandLegacy: EventEmitter<CollapsibleEventDetail>;

componentWillLoad() {
const j = i++;
Expand All @@ -60,7 +65,7 @@ export class Collapsible {

handleClick = () => {
this.expanded = !this.expanded;
this.scaleExpand.emit({ expanded: this.expanded });
emitEvent(this, 'scaleExpand', { expanded: this.expanded });
};

/**
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/components/collapsible/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

## Events

| Event | Description | Type |
| ------------- | -------------------------------------------------- | ------------------------------------- |
| `scaleExpand` | Emitted so parent <scale-accordion> knows about it | `CustomEvent<CollapsibleEventDetail>` |
| Event | Description | Type |
| -------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------- |
| `scale-expand` | Emitted so parent <scale-accordion> knows about it | `CustomEvent<CollapsibleEventDetail>` |
| `scaleExpand` | <span style="color:red">**[DEPRECATED]**</span> in v3 in favor of kebab-case event names<br/><br/> | `CustomEvent<CollapsibleEventDetail>` |


## Shadow Parts
Expand Down
18 changes: 13 additions & 5 deletions packages/components/src/components/data-grid/data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from './data-grid-cells';
import classNames from 'classnames';
import statusNote from '../../utils/status-note';
import { emitEvent } from '../../utils/utils';

// [ ] add options to show nested content without the html column
// [ ] add options to pre-expand all html content
Expand Down Expand Up @@ -110,10 +111,17 @@ export class DataGrid {

/* 4. Events (alphabetical) */
/** Event triggered every time the editable cells are changed, updating the original rows data */
@Event() scaleEdit: EventEmitter<DataGridEditEventDetail>;
@Event({ eventName: 'scale-edit' })
scaleEdit: EventEmitter<DataGridEditEventDetail>;
/** @deprecated in v3 in favor of kebab-case event names */
@Event({ eventName: 'scaleEdit' })
scaleEditLegacy: EventEmitter<DataGridEditEventDetail>;
/** Event triggered every time the data is sorted, changing original rows data */
@Event() scaleSort: EventEmitter<DataGridSortedEventDetail>;

@Event({ eventName: 'scale-sort' })
scaleSort: EventEmitter<DataGridSortedEventDetail>;
/** @deprecated in v3 in favor of kebab-case event names */
@Event({ eventName: 'scaleSort' })
scaleSortLegacy: EventEmitter<DataGridSortedEventDetail>;
/* 5. Private Properties (alphabetical) */
/** Used to update column divider during interaction */
private activeDivider: any;
Expand Down Expand Up @@ -691,7 +699,7 @@ export class DataGrid {
sortDirection,
columnIndex,
} as DataGridSortedEventDetail;
this.scaleSort.emit(data);
emitEvent(this, 'scaleSort', data);
}

triggerEditEvent(value, rowIndex, columnIndex) {
Expand All @@ -701,7 +709,7 @@ export class DataGrid {
columnIndex,
value,
} as DataGridEditEventDetail;
this.scaleEdit.emit(data);
emitEvent(this, 'scaleEdit', data);

// Force render for checkboxes
this.forceRender++;
Expand Down
10 changes: 6 additions & 4 deletions packages/components/src/components/data-grid/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@

## Events

| Event | Description | Type |
| ----------- | ------------------------------------------------------------------------------------------ | ---------------------------------------- |
| `scaleEdit` | Event triggered every time the editable cells are changed, updating the original rows data | `CustomEvent<DataGridEditEventDetail>` |
| `scaleSort` | Event triggered every time the data is sorted, changing original rows data | `CustomEvent<DataGridSortedEventDetail>` |
| Event | Description | Type |
| ------------ | -------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| `scale-edit` | Event triggered every time the editable cells are changed, updating the original rows data | `CustomEvent<DataGridEditEventDetail>` |
| `scale-sort` | Event triggered every time the data is sorted, changing original rows data | `CustomEvent<DataGridSortedEventDetail>` |
| `scaleEdit` | <span style="color:red">**[DEPRECATED]**</span> in v3 in favor of kebab-case event names<br/><br/> | `CustomEvent<DataGridEditEventDetail>` |
| `scaleSort` | <span style="color:red">**[DEPRECATED]**</span> in v3 in favor of kebab-case event names<br/><br/> | `CustomEvent<DataGridSortedEventDetail>` |


## Dependencies
Expand Down
28 changes: 22 additions & 6 deletions packages/components/src/components/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import classNames from 'classnames';
import { DuetLocalizedText } from '@duetds/date-picker/dist/types/components/duet-date-picker/date-localization';
import statusNote from '../../utils/status-note';
import { emitEvent } from '../../utils/utils';

let i = 0;

Expand Down Expand Up @@ -151,17 +152,32 @@ export class DatePicker {
/**
* Event emitted when a date is selected.
*/
@Event() scaleChange: EventEmitter<DuetDatePickerChangeEvent>;
@Event({ eventName: 'scale-change' })
scaleChange: EventEmitter<DuetDatePickerChangeEvent>;

/** @deprecated in v3 in favor of kebab-case event names */
@Event({ eventName: 'scaleChange' })
scaleChangeLegacy: EventEmitter<DuetDatePickerChangeEvent>;

/**
* Event emitted the date picker input is blurred.
*/
@Event() scaleBlur: EventEmitter<DuetDatePickerFocusEvent>;
@Event({ eventName: 'scale-blur' })
scaleBlur: EventEmitter<DuetDatePickerFocusEvent>;

/** @deprecated in v3 in favor of kebab-case event names */
@Event({ eventName: 'scaleBlur' })
scaleBlurLegacy: EventEmitter<DuetDatePickerFocusEvent>;

/**
* Event emitted the date picker input is focused.
*/
@Event() scaleFocus: EventEmitter<DuetDatePickerFocusEvent>;
@Event({ eventName: 'scale-focus' })
scaleFocus: EventEmitter<DuetDatePickerFocusEvent>;

/** @deprecated in v3 in favor of kebab-case event names */
@Event({ eventName: 'scaleFocus' })
scaleFocusLegacy: EventEmitter<DuetDatePickerFocusEvent>;

private helperTextId = `helper-message-${i}`;

Expand Down Expand Up @@ -283,15 +299,15 @@ export class DatePicker {
</label>
<duet-date-picker
onDuetChange={(e) => {
this.scaleChange.emit(e.detail);
emitEvent(this, 'scaleChange', e.detail);
this.handleKeyPress(e);
}}
onDuetFocus={(e) => {
this.scaleFocus.emit(e.detail);
emitEvent(this, 'scaleFocus', e.detail);
this.hasFocus = true;
}}
onDuetBlur={(e) => {
this.scaleBlur.emit(e.detail);
emitEvent(this, 'scaleBlur', e.detail);
this.hasFocus = false;
}}
name={this.name}
Expand Down
13 changes: 8 additions & 5 deletions packages/components/src/components/date-picker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@

## Events

| Event | Description | Type |
| ------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------- |
| `scaleBlur` | Event emitted the date picker input is blurred. | `CustomEvent<{ component: "duet-date-picker"; }>` |
| `scaleChange` | Event emitted when a date is selected. | `CustomEvent<{ component: "duet-date-picker"; valueAsDate: Date; value: string; }>` |
| `scaleFocus` | Event emitted the date picker input is focused. | `CustomEvent<{ component: "duet-date-picker"; }>` |
| Event | Description | Type |
| -------------- | -------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `scale-blur` | Event emitted the date picker input is blurred. | `CustomEvent<{ component: "duet-date-picker"; }>` |
| `scale-change` | Event emitted when a date is selected. | `CustomEvent<{ component: "duet-date-picker"; valueAsDate: Date; value: string; }>` |
| `scale-focus` | Event emitted the date picker input is focused. | `CustomEvent<{ component: "duet-date-picker"; }>` |
| `scaleBlur` | <span style="color:red">**[DEPRECATED]**</span> in v3 in favor of kebab-case event names<br/><br/> | `CustomEvent<{ component: "duet-date-picker"; }>` |
| `scaleChange` | <span style="color:red">**[DEPRECATED]**</span> in v3 in favor of kebab-case event names<br/><br/> | `CustomEvent<{ component: "duet-date-picker"; valueAsDate: Date; value: string; }>` |
| `scaleFocus` | <span style="color:red">**[DEPRECATED]**</span> in v3 in favor of kebab-case event names<br/><br/> | `CustomEvent<{ component: "duet-date-picker"; }>` |


## Methods
Expand Down
Loading