-
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.
- Loading branch information
1 parent
9acd899
commit 9113322
Showing
20 changed files
with
185 additions
and
134 deletions.
There are no files selected for viewing
11 changes: 8 additions & 3 deletions
11
packages/libraries/core/src/components/clipboard/ods-clipboard-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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { OdsComponentAttributes } from '../ods-component-attributes'; | ||
|
||
export interface OdsClipboardAttributes extends OdsComponentAttributes { | ||
/** | ||
* Clipboard attribute description | ||
*/ | ||
/** Indicates if the input is full width or not: see component principles */ | ||
flex?: boolean; | ||
|
||
/** Input text value */ | ||
value: string; | ||
|
||
/** Disabled the input, the focus, and the tooltip */ | ||
disabled?: boolean; | ||
} |
13 changes: 3 additions & 10 deletions
13
packages/libraries/core/src/components/clipboard/ods-clipboard-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,21 +1,14 @@ | ||
import { OdsClipboard } from './ods-clipboard'; | ||
import { OdsComponentController } from '../ods-component-controller'; | ||
import { writeOnClipboard } from '../../utils/clipboard/write-on-clipboard'; | ||
|
||
/** | ||
* 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 OdsClipboardController extends OdsComponentController<OdsClipboard> { | ||
// private readonly logger = new OdsLogger('OdsClipboardController'); | ||
|
||
constructor(component: OdsClipboard) { | ||
super(component); | ||
} | ||
|
||
/** | ||
* Attributes validation documentation | ||
*/ | ||
validateAttributes(): void { | ||
return; | ||
async handlerClick(value: string): Promise<void> { | ||
await writeOnClipboard(value); | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
packages/libraries/core/src/components/clipboard/ods-clipboard-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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { OdsClipboardAttributes } from './ods-clipboard-attributes'; | ||
|
||
export const odsClipboardDefaultAttributesDoc = { | ||
// default attributes | ||
export const odsClipboardDefaultAttributesDoc = { | ||
flex: false, | ||
value: '', | ||
disabled: false, | ||
} as const; | ||
|
||
export const odsClipboardDefaultAttributes = odsClipboardDefaultAttributesDoc as OdsClipboardAttributes; |
2 changes: 1 addition & 1 deletion
2
packages/libraries/core/src/components/clipboard/ods-clipboard-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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { OdsComponentEvents } from '../ods-component-events'; | ||
|
||
export interface OdsClipboardEvents extends OdsComponentEvents { | ||
// Events | ||
odsClipboardCopied: string; | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/libraries/core/src/utils/clipboard/write-on-clipboard.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,4 @@ | ||
export function writeOnClipboard(textToWrite: string): Promise<void> { | ||
console.log('test', textToWrite); | ||
return navigator.clipboard.writeText(textToWrite); | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/specifications/components/clipboard/specifications-clipboard.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
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
36 changes: 32 additions & 4 deletions
36
packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.e2e.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,28 +1,56 @@ | ||
import { E2EElement, E2EPage, newE2EPage } from '@stencil/core/testing'; | ||
import { OdsClipboardAttributes, OdsComponentAttributes2StringAttributes, odsClipboardDefaultAttributes } from '@ovhcloud/ods-core'; | ||
import { OdsCreateAttributes, OdsStringAttributes2Str, odsClipboardBaseAttributes } from '@ovhcloud/ods-testing'; | ||
import { OdsCreateAttributes, OdsStringAttributes2Str } from '@ovhcloud/ods-testing'; | ||
|
||
describe('e2e:osds-clipboard', () => { | ||
let page: E2EPage; | ||
let el: E2EElement; | ||
let input: E2EElement; | ||
|
||
async function setup({ attributes }: { attributes: Partial<OdsClipboardAttributes> }) { | ||
const minimalAttributes: OdsClipboardAttributes = OdsCreateAttributes(attributes, odsClipboardBaseAttributes); | ||
const minimalAttributes: OdsClipboardAttributes = OdsCreateAttributes(attributes, odsClipboardDefaultAttributes); | ||
const stringAttributes = OdsComponentAttributes2StringAttributes<OdsClipboardAttributes>(minimalAttributes, odsClipboardDefaultAttributes); | ||
|
||
page = await newE2EPage(); | ||
const origin = await page.evaluate(() => window.origin); | ||
|
||
const browserContext = page.browserContext(); | ||
await browserContext.overridePermissions(origin, ['clipboard-write', 'clipboard-read']); | ||
await page.setContent(`<osds-clipboard ${OdsStringAttributes2Str(stringAttributes)}></osds-clipboard>`); | ||
await page.evaluate(() => document.body.style.setProperty('margin', '0px')); | ||
|
||
el = await page.find('osds-clipboard'); | ||
input = await page.find('osds-clipboard >>> osds-input'); | ||
await page.waitForChanges(); | ||
} | ||
|
||
it('should render', async () => { | ||
await setup({ attributes: {} }); | ||
expect(el).not.toBeNull(); | ||
expect(el).toHaveClass('hydrated'); | ||
|
||
// E2E testing | ||
expect(input).not.toBeNull(); | ||
expect(input).toHaveClass('hydrated'); | ||
}); | ||
|
||
it.only('should copy the input value', async () => { | ||
const value = 'text to copy'; | ||
|
||
await setup({ attributes: { value } }); | ||
|
||
await input.click(); | ||
|
||
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(value); | ||
}); | ||
|
||
// it('should not copy the input value because of disabled', async () => { | ||
// const value = 'text to copy'; | ||
// await setup({ attributes: { value, disabled: true } }); | ||
// await page.evaluate(() => navigator.clipboard.writeText('')); | ||
|
||
// await input.click(); | ||
|
||
// expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(''); | ||
// }); | ||
|
||
}); |
21 changes: 0 additions & 21 deletions
21
packages/stencil/components/clipboard/src/components/osds-clipboard/osds-clipboard.scss
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,24 +1,3 @@ | ||
@import 'styles/osds-clipboard.mixins'; | ||
@import 'styles/osds-clipboard.color'; | ||
@import 'styles/osds-clipboard.size'; | ||
@import 'styles/osds-clipboard.typography'; | ||
@import '~@ovhcloud/ods-theming/color/ods-theming-color'; | ||
@import '~@ovhcloud/ods-theming/ods-theme'; | ||
|
||
// CSS targeted only for this component | ||
// /!\ for theming purposes, it has to be done in theming files | ||
// (i.e. packages/libraries/theming/...) | ||
:host { | ||
|
||
} | ||
|
||
:host([attribute]) { | ||
|
||
} | ||
|
||
// apply the theme template for the component | ||
@include ods-theme-component() { | ||
@include osds-clipboard-theme-color(); | ||
@include osds-clipboard-theme-size(); | ||
@include osds-clipboard-theme-typography(); | ||
} |
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
Oops, something went wrong.