diff --git a/src/components/component-names.ts b/src/components/component-names.ts index a6dc3a639..eeaea1851 100644 --- a/src/components/component-names.ts +++ b/src/components/component-names.ts @@ -14,6 +14,7 @@ export const CHIP_NAME: string = 'm-chip'; export const CHIP_ADD_NAME: string = 'm-chip-add'; export const CHIP_DELETE_NAME: string = 'm-chip-delete'; export const COPY_TO_CLIPBOARD_NAME: string = 'm-copy-to-clipboard'; +export const COPY_TO_CLIPBOARD_FEEDBACK_NAME: string = 'm-copy-to-clipboard-feedback'; export const DATEFIELDS_NAME: string = 'm-datefields'; export const DATEPICKER_NAME: string = 'm-datepicker'; export const DATERANGEPICKER_NAME: string = 'm-daterangepicker'; diff --git a/src/components/copy-to-clipboard/__snapshots__/copy-to-clipboard.stories.ts.snap b/src/components/copy-to-clipboard/__snapshots__/copy-to-clipboard.stories.ts.snap index 5ebe7be1e..61fb4a87b 100644 --- a/src/components/copy-to-clipboard/__snapshots__/copy-to-clipboard.stories.ts.snap +++ b/src/components/copy-to-clipboard/__snapshots__/copy-to-clipboard.stories.ts.snap @@ -88,6 +88,103 @@ exports[`Storyshots components|m-copy-to-clipboard custom 1`] = ` `; +exports[`Storyshots components|m-copy-to-clipboard custom user feedback 1`] = ` +
+
+
+
+
+ + + + +
+
+ +
+ + + + + + + +
+ + +
+
+ + +
+
+ +
+
+ + + +
+ + +
+
+
+`; + exports[`Storyshots components|m-copy-to-clipboard default 1`] = `
`; + +exports[`Storyshots components|m-copy-to-clipboard user feedback 1`] = ` +
+
+
+
+
+ + + + +
+
+ +
+ + + + + + + +
+ + +
+
+ + +
+
+ +
+
+ + + +
+ + +
+
+
+`; diff --git a/src/components/copy-to-clipboard/copy-to-clipboard-feedback.ts b/src/components/copy-to-clipboard/copy-to-clipboard-feedback.ts new file mode 100644 index 000000000..ba34ce975 --- /dev/null +++ b/src/components/copy-to-clipboard/copy-to-clipboard-feedback.ts @@ -0,0 +1,53 @@ +import { PluginObject, VNode } from 'vue'; +import Component from 'vue-class-component'; +import { Prop } from 'vue-property-decorator'; +import { ModulVue } from '../../utils/vue/vue'; +import { COPY_TO_CLIPBOARD_FEEDBACK_NAME } from '../component-names'; +import I18nPlugin from '../i18n/i18n'; +import TextfieldPlugin from '../textfield/textfield'; +import ToastPlugin, { MToastPosition, MToastTimeout } from '../toast/toast'; + +@Component +export class MCopyToClipboardFeedback extends ModulVue { + @Prop() + message: string; + + @Prop({ + default: MToastPosition.BottomRight + }) + position: MToastPosition; + + @Prop({ + default: MToastTimeout.xshort + }) + timeout: MToastTimeout; + + render(): VNode { + if (this.$scopedSlots && this.$scopedSlots.default) { + return this.$scopedSlots.default({ + showToast: () => this.showToast() + }) as any; + } else { + throw new Error('copy-to-clipboard expects a default scoped slot.'); + } + } + + showToast(): void { + this.$toast.show({ + text: this.message ? this.message : this.$i18n.translate('m-copy-to-clipboard:copied'), + position: this.position, + timeout: this.timeout + }); + } +} + +const CopyToClipboardFeedbackPlugin: PluginObject = { + install(v): void { + v.component(COPY_TO_CLIPBOARD_FEEDBACK_NAME, MCopyToClipboardFeedback); + v.use(I18nPlugin); + v.use(TextfieldPlugin); + v.use(ToastPlugin); + } +}; + +export default CopyToClipboardFeedbackPlugin; diff --git a/src/components/copy-to-clipboard/copy-to-clipboard.html b/src/components/copy-to-clipboard/copy-to-clipboard.html index da4e12ae9..182ab8a60 100644 --- a/src/components/copy-to-clipboard/copy-to-clipboard.html +++ b/src/components/copy-to-clipboard/copy-to-clipboard.html @@ -4,7 +4,6 @@ :handlers="inputHandlers"> -