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: copy button #199

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
"dev:storybook": "storybook dev -p 6006 -s dist"
},
"dependencies": {
"@capacitor/clipboard": "^6.0.2",
"@stencil/core": "^4.11.0",
"@tailwindcss/line-clamp": "^0.4.4",
"ansi-to-html": "^0.7.2",
12,273 changes: 6,753 additions & 5,520 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
@@ -50,6 +50,10 @@ export namespace Components {
"checked": boolean;
"error": string | undefined;
}
interface DCopyButton {
"delay": number;
"textToCopy": string;
}
interface DCredentialCard {
"expirationDate"?: string;
"expirationLabel": string;
@@ -323,6 +327,12 @@ declare global {
prototype: HTMLDCheckboxElement;
new (): HTMLDCheckboxElement;
};
interface HTMLDCopyButtonElement extends Components.DCopyButton, HTMLStencilElement {
}
var HTMLDCopyButtonElement: {
prototype: HTMLDCopyButtonElement;
new (): HTMLDCopyButtonElement;
};
interface HTMLDCredentialCardElement extends Components.DCredentialCard, HTMLStencilElement {
}
var HTMLDCredentialCardElement: {
@@ -577,6 +587,7 @@ declare global {
"d-button": HTMLDButtonElement;
"d-buttons-group": HTMLDButtonsGroupElement;
"d-checkbox": HTMLDCheckboxElement;
"d-copy-button": HTMLDCopyButtonElement;
"d-credential-card": HTMLDCredentialCardElement;
"d-credential-detail": HTMLDCredentialDetailElement;
"d-credential-service": HTMLDCredentialServiceElement;
@@ -654,6 +665,10 @@ declare namespace LocalJSX {
"error"?: string | undefined;
"onDChange"?: (event: DCheckboxCustomEvent<boolean>) => void;
}
interface DCopyButton {
"delay"?: number;
"textToCopy"?: string;
}
interface DCredentialCard {
"expirationDate"?: string;
"expirationLabel"?: string;
@@ -844,6 +859,7 @@ declare namespace LocalJSX {
"d-button": DButton;
"d-buttons-group": DButtonsGroup;
"d-checkbox": DCheckbox;
"d-copy-button": DCopyButton;
"d-credential-card": DCredentialCard;
"d-credential-detail": DCredentialDetail;
"d-credential-service": DCredentialService;
@@ -889,6 +905,7 @@ declare module "@stencil/core" {
"d-button": LocalJSX.DButton & JSXBase.HTMLAttributes<HTMLDButtonElement>;
"d-buttons-group": LocalJSX.DButtonsGroup & JSXBase.HTMLAttributes<HTMLDButtonsGroupElement>;
"d-checkbox": LocalJSX.DCheckbox & JSXBase.HTMLAttributes<HTMLDCheckboxElement>;
"d-copy-button": LocalJSX.DCopyButton & JSXBase.HTMLAttributes<HTMLDCopyButtonElement>;
"d-credential-card": LocalJSX.DCredentialCard & JSXBase.HTMLAttributes<HTMLDCredentialCardElement>;
"d-credential-detail": LocalJSX.DCredentialDetail & JSXBase.HTMLAttributes<HTMLDCredentialDetailElement>;
"d-credential-service": LocalJSX.DCredentialService & JSXBase.HTMLAttributes<HTMLDCredentialServiceElement>;
2 changes: 2 additions & 0 deletions src/components/button/readme.md
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@

### Used by

- [d-copy-button](../copy-button)
- [d-empty-state](../empty-state)
- [d-input](../input)
- [d-scan-button](../scan-button)
@@ -40,6 +41,7 @@
### Graph
```mermaid
graph TD;
d-copy-button --> d-button
d-empty-state --> d-button
d-input --> d-button
d-scan-button --> d-button
3 changes: 3 additions & 0 deletions src/components/copy-button/d-copy-button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {
display: block;
}
34 changes: 34 additions & 0 deletions src/components/copy-button/d-copy-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Component, h, Prop, State } from '@stencil/core';
import { Clipboard } from '@capacitor/clipboard';
// import { clipboardOutline, checkmarkOutline } from 'ionicons/icons';

@Component({
tag: 'd-copy-button',
styleUrl: 'd-copy-button.css',
shadow: true,
})
export class DCopyButton {
@Prop() textToCopy: string;
@Prop() delay: number = 2000;
@State() isCopied: boolean = false;

async copyText() {
await Clipboard.write({
string: this.textToCopy,
});

this.isCopied = true;

setTimeout(() => {
this.isCopied = false;
}, this.delay);
}

render() {
return (
<d-button role="button" onClick={() => this.copyText()} color="outline" class="text-on" expand>
{!this.isCopied ? 'Copy' : 'Copied!'}
</d-button>
);
}
}
36 changes: 36 additions & 0 deletions src/components/copy-button/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# d-copy-button



<!-- Auto Generated Below -->


## Properties

| Property | Attribute | Description | Type | Default |
| ------------ | -------------- | ----------- | -------- | ----------- |
| `delay` | `delay` | | `number` | `2000` |
| `textToCopy` | `text-to-copy` | | `string` | `undefined` |


## Dependencies

### Used by

- [d-feedback](../feedback)

### Depends on

- [d-button](../button)

### Graph
```mermaid
graph TD;
d-copy-button --> d-button
d-feedback --> d-copy-button
style d-copy-button fill:#f9f,stroke:#333,stroke-width:4px
```

----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
11 changes: 11 additions & 0 deletions src/components/copy-button/test/d-copy-button.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { newE2EPage } from '@stencil/core/testing';

describe('d-copy-button', () => {
it('renders', async () => {
const page = await newE2EPage();
await page.setContent('<d-copy-button></d-copy-button>');

const element = await page.find('d-copy-button');
expect(element).toHaveClass('hydrated');
});
});
20 changes: 20 additions & 0 deletions src/components/copy-button/test/d-copy-button.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { newSpecPage } from '@stencil/core/testing';
import { DCopyButton } from '../d-copy-button';

describe('d-copy-button', () => {
it('renders', async () => {
const page = await newSpecPage({
components: [DCopyButton],
html: `<d-copy-button></d-copy-button>`,
});
expect(page.root).toEqualHtml(`
<d-copy-button>
<mock:shadow-root>
<d-button class="text-on" color="outline" expand="" role="button">
Copy
</d-button>
</mock:shadow-root>
</d-copy-button>
`);
});
});
3 changes: 2 additions & 1 deletion src/components/feedback/d-feedback.tsx
Original file line number Diff line number Diff line change
@@ -87,7 +87,8 @@ export class DFeedback {
<div class="flex flex-col gap-2 items-start break-all">
{!this.hide && (
<d-text size="s" class="text-on-alt">
<div innerHTML={converter.toHtml(this.message)} />
<div class="break-words" innerHTML={converter.toHtml(this.message)} />
<d-copy-button textToCopy={this.message} >Copy</d-copy-button>
</d-text>
)}
<button onClick={onClick} class="h-12 text-on text-base font-bold leading-5 underline">
3 changes: 3 additions & 0 deletions src/components/feedback/readme.md
Original file line number Diff line number Diff line change
@@ -26,11 +26,14 @@
### Depends on

- [d-text](../text)
- [d-copy-button](../copy-button)

### Graph
```mermaid
graph TD;
d-feedback --> d-text
d-feedback --> d-copy-button
d-copy-button --> d-button
style d-feedback fill:#f9f,stroke:#333,stroke-width:4px
```