-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(arch): move && simplify component collapsible
- Loading branch information
Showing
83 changed files
with
993 additions
and
294 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions
62
packages-new/components/collapsible/documentation/specifications/spec.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
* [**Interfaces**](#interfaces) | ||
* [**Classes**](#classes) | ||
* [**Type alias**](#type-alias) | ||
* [**Variables**](#variables) | ||
|
||
## Interfaces | ||
|
||
### OdsCollapsibleAttributes | ||
|name | Type | Required | Default | Description| | ||
|---|---|:---:|---|---| | ||
|**`opened`** | _boolean_ | | | opened or not| | ||
|
||
### OdsCollapsibleBehavior | ||
|name | Type | Required | Default | Description| | ||
|---|---|:---:|---|---| | ||
|**`el`** | `HTMLElement` | ✴️ | | reference to the host element.| | ||
|**`emitToggle`** | _void_ | ✴️ | | emit collapsible opened status when toggle event is triggered| | ||
|
||
### OdsCollapsibleEvents | ||
|name | Type | Required | Default | Description| | ||
|---|---|:---:|---|---| | ||
|**`odsCollapsibleToggle`** | _boolean_ | ✴️ | | Event triggered on collapsible toggle| | ||
|
||
## Classes | ||
|
||
### OdsCollapsibleController | ||
_common controller logic for cmpnt component used by the different implementations._ | ||
_it contains all the glue between framework implementation and the third party service._ | ||
|
||
#### Methods | ||
> **onToggle**() => _unknown_ | ||
|
||
|
||
## Type alias | ||
|
||
### OdsCollapsible | ||
|
||
interface description of all implementation of `ods-collapsible`. | ||
each implementation must have defined events, methods, attributes | ||
and one controller for the common behavior logic | ||
|
||
> - `OdsComponentGenericMethods` | ||
> - `OdsComponentGenericEvents` | ||
### OdsCollapsibleAttributes | ||
|
||
> _Based on `OdsComponentAttributes`_ | ||
### OdsCollapsibleEvents | ||
|
||
> _Based on `OdsComponentEvents`_ | ||
### OdsCollapsibleMethods | ||
|
||
> _Based on `OdsComponentMethods`_ | ||
## Variables | ||
|
||
### odsCollapsibleDefaultAttributes | ||
`OdsCollapsibleAttributes` |
4 changes: 4 additions & 0 deletions
4
...ponents/collapsible/documentation/specifications/specifications-collapsible.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {Description} from '@storybook/addon-docs'; | ||
import Specs from './spec.md'; | ||
|
||
<Description>{Specs}</Description> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
...ew/components/collapsible/src/components/osds-collapsible/constants/default-attributes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { OdsCollapsibleAttribute } from '../interfaces/attributes'; | ||
|
||
const DEFAULT_ATTRIBUTE: OdsCollapsibleAttribute = Object.freeze({ | ||
opened: false, | ||
}); | ||
|
||
export { | ||
DEFAULT_ATTRIBUTE, | ||
}; |
37 changes: 37 additions & 0 deletions
37
packages-new/components/collapsible/src/components/osds-collapsible/core/controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { EventEmitter } from '@stencil/core'; | ||
import { OdsCollapsibleController } from './controller'; | ||
import { OsdsCollapsible } from '../osds-collapsible'; | ||
|
||
class OdsCollapsibleMock extends OsdsCollapsible { | ||
constructor(attribute: Partial<OsdsCollapsible>) { | ||
super(); | ||
Object.assign(this, attribute); | ||
} | ||
} | ||
|
||
describe('spec:ods-collapsible-controller', () => { | ||
let controller: OdsCollapsibleController; | ||
let component: OsdsCollapsible; | ||
|
||
function setup(attributes: Partial<OsdsCollapsible> = {}) { | ||
component = new OdsCollapsibleMock(attributes); | ||
component.odsCollapsibleToggle = { emit: jest.fn() } as unknown as EventEmitter<boolean>; | ||
controller = new OdsCollapsibleController(component); | ||
} | ||
|
||
describe('methods:onToggle', () => { | ||
it('should odsCollapsibleToggle emit false', () => { | ||
setup({ opened: true }); | ||
const spy = jest.spyOn(component, 'emitToggle'); | ||
controller.onToggle(); | ||
expect(spy).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('should odsCollapsibleToggle emit true', () => { | ||
setup({ opened: false }); | ||
const spy = jest.spyOn(component, 'emitToggle'); | ||
controller.onToggle(); | ||
expect(spy).toHaveBeenCalledWith(false); | ||
}); | ||
}); | ||
}); |
14 changes: 9 additions & 5 deletions
14
...collapsible/ods-collapsible-controller.ts → ...nents/osds-collapsible/core/controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import { OdsCollapsible } from './ods-collapsible'; | ||
import { OdsComponentController } from '../ods-component-controller'; | ||
import type { OsdsCollapsible } from '../osds-collapsible'; | ||
|
||
/** | ||
* common controller logic for cmpnt component used by the different implementations. | ||
* it contains all the glue between framework implementation and the third party service. | ||
*/ | ||
export class OdsCollapsibleController extends OdsComponentController<OdsCollapsible> { | ||
class OdsCollapsibleController { | ||
private component: OsdsCollapsible; | ||
|
||
constructor(component: OdsCollapsible) { | ||
super(component); | ||
constructor(component: OsdsCollapsible) { | ||
this.component = component; | ||
} | ||
|
||
onToggle(): void { | ||
this.component.emitToggle(this.component.opened || false); | ||
} | ||
} | ||
|
||
export { | ||
OdsCollapsibleController, | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages-new/components/collapsible/src/components/osds-collapsible/interfaces/attributes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface OdsCollapsibleAttribute { | ||
/** opened or not */ | ||
opened?: boolean; | ||
} | ||
|
||
export { | ||
OdsCollapsibleAttribute, | ||
}; |
12 changes: 12 additions & 0 deletions
12
packages-new/components/collapsible/src/components/osds-collapsible/interfaces/events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { EventEmitter } from '@stencil/core'; | ||
|
||
interface OdsCollapsibleEvent { | ||
/** | ||
* Event triggered on collapsible toggle | ||
*/ | ||
odsCollapsibleToggle: EventEmitter<boolean>; | ||
} | ||
|
||
export { | ||
OdsCollapsibleEvent, | ||
}; |
21 changes: 8 additions & 13 deletions
21
...psible/osds-collapsible.e2e.screenshot.ts → ...psible/osds-collapsible.e2e.screenshot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.