diff --git a/CHANGELOG.md b/CHANGELOG.md index 16a4d83..0bb2a86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -130,6 +130,7 @@ - SSR support - Provide separate ESM and UMD builds - `color` and `without-content-background` props to ipl-expanding-space +- Added `copiable` to ipl-data-row # 2.10.1 diff --git a/docs/examples/DataRowExample.vue b/docs/examples/DataRowExample.vue index 852c202..543fe84 100644 --- a/docs/examples/DataRowExample.vue +++ b/docs/examples/DataRowExample.vue @@ -4,6 +4,7 @@ @@ -18,6 +19,10 @@ name="value" label="Value" /> + @@ -25,7 +30,9 @@ import IplDataRow from '../../src/components/iplDataRow.vue'; import { ref } from 'vue'; import IplInput from '../../src/components/iplInput.vue'; +import IplCheckbox from '../../src/components/iplCheckbox.vue'; const label = ref('Data Row'); const value = ref('text content'); +const copiable = ref(false); diff --git a/src/components/__tests__/iplDataRow.test.ts b/src/components/__tests__/iplDataRow.test.ts index dffac8a..f4fcbdd 100644 --- a/src/components/__tests__/iplDataRow.test.ts +++ b/src/components/__tests__/iplDataRow.test.ts @@ -25,4 +25,27 @@ describe('IplDataRow', () => { expect(wrapper.get('.value').text()).toEqual('Value!'); }); + + it('does not show copy button by default', () => { + const wrapper = mount(IplDataRow, { props: { label: 'Label!', value: 'Value!' } }); + + expect(wrapper.find('.copy-button').exists()).toEqual(false); + }); + + it('shows copy button when enabled', () => { + const wrapper = mount(IplDataRow, { props: { label: 'Label!', value: 'Value!', copiable: true } }); + + expect(wrapper.find('.copy-button').exists()).toEqual(true); + }); + + it('copies value on copy button click', async () => { + const wrapper = mount(IplDataRow, { props: { label: 'Label!', value: 'Value!', copiable: true } }); + Object.defineProperty(navigator, 'clipboard', { + value: { writeText: jest.fn().mockResolvedValue(undefined) } + }); + + await wrapper.get('.copy-button').trigger('click'); + + expect(navigator.clipboard.writeText).toHaveBeenCalledWith('Value!'); + }); }); diff --git a/src/components/iplDataRow.vue b/src/components/iplDataRow.vue index b884083..bcb526b 100755 --- a/src/components/iplDataRow.vue +++ b/src/components/iplDataRow.vue @@ -1,31 +1,65 @@ {{ label }} - {{ value ?? '―' }} + + {{ isBlank(value) ? '―' : value }} + + + + diff --git a/src/components/iplMessage.vue b/src/components/iplMessage.vue index 2f12fbb..22f42de 100644 --- a/src/components/iplMessage.vue +++ b/src/components/iplMessage.vue @@ -104,16 +104,20 @@ export default defineComponent({ height: 1.1em; border: 0; background-color: transparent; - color: var(--ipl-body-text-color); + color: var(--ipl-text-button-color); cursor: default; border-radius: constants.$border-radius-inner; text-align: center; + transition-property: color, background-color; + transition-duration: constants.$transition-duration-low; &:hover { + color: var(--ipl-text-button-color-hover); background-color: var(--ipl-hover-overlay-color); } &:active { + color: var(--ipl-text-button-color-active); background-color: var(--ipl-active-overlay-color); } diff --git a/src/helpers/stringHelper.ts b/src/helpers/stringHelper.ts index 29e7300..e4a15ea 100644 --- a/src/helpers/stringHelper.ts +++ b/src/helpers/stringHelper.ts @@ -18,5 +18,5 @@ export function formatNumber(value: number): string { } export function isBlank(value?: string | null): boolean { - return value === null || value === undefined || value.trim() === ''; + return value === null || value === undefined || String(value).trim() === ''; } diff --git a/src/styles/variables-light.scss b/src/styles/variables-light.scss index 0bc569b..7872e75 100644 --- a/src/styles/variables-light.scss +++ b/src/styles/variables-light.scss @@ -14,6 +14,9 @@ html.light { --ipl-body-text-color: #3C3C43; --ipl-disabled-body-text-color: #9494A0; + --ipl-text-button-color: rgba(60, 60, 67, 0.5); + --ipl-text-button-color-hover: rgba(60, 60, 67, 0.75); + --ipl-text-button-color-active: rgba(60, 60, 67, 0.9); --ipl-bg-primary: #FFFFFF; --ipl-bg-primary-hover: #F2F2F2; diff --git a/src/styles/variables.scss b/src/styles/variables.scss index c09fb9e..da4eafe 100644 --- a/src/styles/variables.scss +++ b/src/styles/variables.scss @@ -16,6 +16,9 @@ html { --ipl-body-text-color: #FFFFFF; --ipl-disabled-body-text-color: #A9AAA9; + --ipl-text-button-color: rgba(255, 255, 255, 0.5); + --ipl-text-button-color-hover: rgba(255, 255, 255, 0.75); + --ipl-text-button-color-active: rgba(255, 255, 255, 0.9); --ipl-bg-primary: #262F40; --ipl-bg-primary-hover: #222a39;