Skip to content

Commit 540f7d7

Browse files
committed
send-feedback: Add option to specify external stylesheet.
1 parent 55210a0 commit 540f7d7

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

docs/customizing.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# customizing
22

3-
This documentation section will guide you through the process,
3+
This documentation section will guide you through the process,
44
of how to customize the `<send-feedback>` element. The one of the great
55
feature of custom elements.
66

7+
### Customize the design
8+
There are two was to provide custom css. Through a css file or
9+
by directly providing css. Set the `customStylesheet` to the link
10+
of the stylesheet to use it. You can also set the `customStyles` to
11+
css you want, for example, `sendFeedback.customStyle = ':host { padding: 10px; }'`.
12+
713
### Title
814

915
The title of an element, the default is `Send Feedback`

docs/index.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ const SendFeedback = require('@electron-elements/send-feedback');
1414
customElements.define('send-feedback', SendFeedback);
1515
```
1616

17-
By default, the element has responsive design out of the box. But if you want to customize
18-
the design of the element you can do:
17+
By default, the element has responsive design out of the box. But if you want
18+
to customize the design of the element you can do:
1919
```javascript
2020
const sendFeedback = document.querySelector('send-feedback');
21+
sendFeedback.customStylesheet = `custom.css`; // link to custom css file!
22+
// OR
2123
sendFeedback.customStyles = `* { padding: 20px }`;
2224
```
2325

2426
To remove default styles you can do `sendFeedback.removeDefaultStyles = true`. **Note:** This
25-
will remove all the styles we ship with this custom elements, which most of the times is not needed,
26-
because you can add custom css to tweak some design as show above.
27+
will remove all the styles we ship with this custom elements, which most of the times is not needed, because you can add custom css to tweak some design as show above.
2728

2829
Once you feel like designs are in place or you like the default design.
2930
You need to use a `reporter` by calling `sendFeedback.useReporter`, for this example we use

lib/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class SendFeedback extends HTMLElement {
4444
'textarea-placeholder',
4545
'button-label',
4646
'cancel-label',
47-
'show-cancel-button'
47+
'show-cancel-button',
48+
'custom-stylesheet'
4849
];
4950
}
5051

@@ -64,6 +65,7 @@ class SendFeedback extends HTMLElement {
6465
this._button = shadowRoot.querySelector('button');
6566
this._cancel = shadowRoot.querySelector('#cancel');
6667
this._loader = shadowRoot.querySelector('.loader');
68+
this._link = shadowRoot.querySelector('link');
6769

6870
this._textarea.addEventListener('input', this._recheckErrorClass);
6971
this._titleInput.addEventListener('input', this._recheckErrorClass);
@@ -218,6 +220,11 @@ class SendFeedback extends HTMLElement {
218220
return;
219221
}
220222

223+
if (updatedAttr == 'custom-stylesheet') {
224+
this._link.href = _new;
225+
return;
226+
}
227+
221228
const el = selectors[updatedAttr];
222229
if (updatedAttr.includes('placeholder')) {
223230
el.setAttribute('placeholder', _new);

lib/templates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ templates.add('send-feedback', `
164164
}
165165
</style>
166166
<style class="custom-styles"></style>
167+
<link rel="stylesheet">
167168
`);
168169

169170
templates.add('send-feedback-content', `

0 commit comments

Comments
 (0)