This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create OcContextualHelper component (#2064)
* Create OcContextualHelper component * Make linter happy
- Loading branch information
Showing
5 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
changelog/unreleased/enhancement-add-contextual-helper-component
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,7 @@ | ||
Enhancement: Add OcContextualHelper | ||
|
||
We've added a contextual helper component to provide more information | ||
based on the context | ||
|
||
https://github.com/owncloud/web/issues/6590 | ||
https://github.com/owncloud/owncloud-design-system/pull/2064 |
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
45 changes: 45 additions & 0 deletions
45
src/components/atoms/OcContextualHelper/OcContextualHelper.spec.js
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,45 @@ | ||
import OcContextualHelper from "./OcContextualHelper.vue" | ||
import { createLocalVue, shallowMount } from "@vue/test-utils" | ||
import GetTextPlugin from "vue-gettext" | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(GetTextPlugin, { | ||
translations: "does-not-matter.json", | ||
silent: true, | ||
}) | ||
|
||
describe("OcContextualHelper", () => { | ||
function getWrapperWithProps(props) { | ||
return shallowMount(OcContextualHelper, { | ||
localVue: localVue, | ||
propsData: props, | ||
stubs: { | ||
OcDrop: true, | ||
}, | ||
}) | ||
} | ||
describe("should use props correctly", () => { | ||
it("should set text prop", () => { | ||
const wrapper = getWrapperWithProps({ text: "test-my-text" }) | ||
expect(wrapper.find(".info-text").text()).toBe("test-my-text") | ||
}) | ||
it("should set list prop", async () => { | ||
const listValues = ["a-list-value", "b-list-value", "c-list-value"] | ||
const wrapper = getWrapperWithProps({ list: listValues }) | ||
const result = wrapper.find(".info-list").text() | ||
listValues.forEach(value => { | ||
expect(result).toContain(value) | ||
}) | ||
}) | ||
it("should set a readMore link", async () => { | ||
const wrapper = getWrapperWithProps({ readMoreLink: "owncloud.design" }) | ||
const attributes = wrapper.find(".info-more-link").attributes() | ||
expect(attributes["href"]).toBe("owncloud.design") | ||
expect(attributes["target"]).toBe("_blank") | ||
}) | ||
it("should set end-text prop", async () => { | ||
const wrapper = getWrapperWithProps({ endText: "test-my-text" }) | ||
expect(wrapper.find(".info-text-end").text()).toBe("test-my-text") | ||
}) | ||
}) | ||
}) |
138 changes: 138 additions & 0 deletions
138
src/components/atoms/OcContextualHelper/OcContextualHelper.vue
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,138 @@ | ||
<template> | ||
<div class="oc-contextual-helper"> | ||
<oc-button :id="buttonId" appearance="raw"> | ||
<oc-icon name="question" fill-type="line" size="small" /> | ||
</oc-button> | ||
<oc-drop :drop-id="dropId" :toggle="toggleId" mode="click" close-on-click> | ||
<div class="info-drop-content"> | ||
<p class="info-text" v-text="text" /> | ||
<ul v-if="list.length" class="info-list oc-pl-l"> | ||
<li v-for="(item, index) in list" :key="index" class="oc-pl-rm"> | ||
{{ item }} | ||
</li> | ||
</ul> | ||
<p class="info-text-end" v-text="endText" /> | ||
<oc-button | ||
v-if="readMoreLink" | ||
v-translate | ||
type="a" | ||
appearance="raw" | ||
size="small" | ||
class="info-more-link" | ||
:href="readMoreLink" | ||
target="_blank" | ||
>Read more</oc-button | ||
> | ||
</div> | ||
</oc-drop> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import uniqueId from "../../../utils/uniqueId" | ||
import OcButton from "../../atoms/OcButton/OcButton.vue" | ||
import OcIcon from "../../atoms/OcIcon/OcIcon.vue" | ||
import OcDrop from "../../atoms/OcDrop/OcDrop.vue" | ||
export default { | ||
name: "OcContextualHelper", | ||
status: "unreleased", | ||
components: { OcButton, OcIcon, OcDrop }, | ||
props: { | ||
text: { | ||
type: String, | ||
required: false, | ||
}, | ||
list: { | ||
type: Array, | ||
required: false, | ||
default: () => [], | ||
}, | ||
endText: { | ||
type: String, | ||
required: false, | ||
}, | ||
readMoreLink: { | ||
type: String, | ||
required: false, | ||
}, | ||
}, | ||
computed: { | ||
dropId() { | ||
return uniqueId("oc-contextual-helper-") | ||
}, | ||
buttonId() { | ||
return `${this.dropId}-button` | ||
}, | ||
toggleId() { | ||
return `#${this.buttonId}` | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.oc-contextual-helper { | ||
display: inline-block; | ||
.oc-button { | ||
vertical-align: middle; | ||
} | ||
.info-drop-content { | ||
font-size: var(--oc-font-size-small); | ||
color: var(--oc-color-text-default); | ||
} | ||
.info-more-link { | ||
font-size: var(--oc-font-size-small) !important; | ||
} | ||
} | ||
</style> | ||
|
||
<docs> | ||
## Examples | ||
A simple example, using only text. | ||
```js | ||
<template> | ||
<div> | ||
<oc-contextual-helper v-bind="helperContent"/> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
computed: { | ||
helperContent() { | ||
return { | ||
text: this.$gettext("Invite persons or groups to access this file or folder."), | ||
} | ||
} | ||
}, | ||
} | ||
</script> | ||
``` | ||
|
||
An example using Text, List, End-Text and Read-More-Link properties. | ||
```js | ||
<template> | ||
<div> | ||
<oc-contextual-helper v-bind="helperContent"/> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
computed: { | ||
helperContent() { | ||
return { | ||
text: this.$gettext("Invite persons or groups to access this file or folder."), | ||
list: [ | ||
this.$gettext("Enter a name or group to share this item"), | ||
this.$gettext("If you share a folder, all of its contents and subfolders will be shared with the entered persons or groups"), | ||
this.$gettext("Invited persons or groups will be notified via e-mail or in-app notification"), | ||
], | ||
endText: this.$gettext("Invited persons can not see who else has access"), | ||
readMoreLink: "https://owncloud.design" | ||
} | ||
} | ||
}, | ||
} | ||
</script> | ||
``` | ||
</docs> |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ font: | |
size: | ||
default: | ||
value: 1rem | ||
small: | ||
value: 0.88rem | ||
medium: | ||
value: 1.25rem | ||
large: | ||
|