Skip to content

Commit

Permalink
feat: other elements changes for sifrr 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityataparia committed Oct 29, 2019
1 parent a954a9e commit b1892b0
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 60 deletions.
2 changes: 1 addition & 1 deletion elements/sifrr-carousel/src/sifrrcarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const template = SifrrDom.template`<style media="screen">
<sifrr-tab-container>
<slot name="content"></slot>
</sifrr-tab-container>
<span id="count"></span>
<span id="count">\${\`\${this.container.active + 1}/\${this.container.total}\`}</span>
</div>
<div id="preview">
<div class="arrow l">
Expand Down
27 changes: 8 additions & 19 deletions elements/sifrr-code-editor/src/sifrrcodeeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@ const template = SifrrDom.template`
<style media="screen">
${style}
</style>
<textarea></textarea>`;
<textarea value="\${this.value}" _input="\${this.input}"></textarea>`;

class SifrrCodeEditor extends SifrrDom.Element {
static get template() {
return template;
}

static observedAttrs() {
return ['value', 'theme', 'lang'];
}

static syncedAttrs() {
return ['theme'];
}

static cm() {
this._cm =
this._cm ||
Expand All @@ -33,11 +25,12 @@ class SifrrCodeEditor extends SifrrDom.Element {
return this._cm;
}

onAttributeChange(n, _, v) {
onPropsChange(props) {
if (this._cmLoaded) {
if (n === 'theme') this.cm.setOption('theme', v);
if (n === 'lang') this.cm.setOption('mode', this.getTheme());
if (props.indexOf('theme') > -1) this.cm.setOption('theme', this.getTheme());
if (props.indexOf('lang') > -1) this.cm.setOption('mode', this.lang || 'xml');
}
if (['value', 'theme', 'lang'].filter(p => props.indexOf(p) > -1).length > 0) this.update();
}

onConnect() {
Expand All @@ -46,10 +39,12 @@ class SifrrCodeEditor extends SifrrDom.Element {

input() {
SifrrDom.Event.trigger(this, 'input');
this.value = this.getValue();
this.update();
}

cmLoaded() {
this.lang = this.lang || 'xml';
SifrrDom.Loader.executeJS(
`https://cdn.jsdelivr.net/npm/codemirror@${CM_VERSION}/mode/${this.lang}/${this.lang}.js`
).then(() => {
Expand All @@ -71,7 +66,7 @@ class SifrrCodeEditor extends SifrrDom.Element {
return this.theme ? this.theme.split(' ')[0] : 'dracula';
}

get value() {
getValue() {
if (this._cmLoaded) return this.cm.getValue();
else return this.$('textarea').value;
}
Expand All @@ -81,12 +76,6 @@ class SifrrCodeEditor extends SifrrDom.Element {
if (this._cmLoaded) return this.cm.setValue(v);
else this.$('textarea').value = v;
}

get lang() {
const attr = this.getAttribute('lang');
if (!attr || attr === 'html') return 'xml';
return attr;
}
}

SifrrDom.register(SifrrCodeEditor);
Expand Down
4 changes: 0 additions & 4 deletions elements/sifrr-include/src/sifrrinclude.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import SifrrDom from '@sifrr/dom';

class SifrrInclude extends SifrrDom.Element {
static syncedAttrs() {
return ['url', 'type', 'selector'];
}

onConnect() {
let preffix = '',
suffix = '';
Expand Down
9 changes: 3 additions & 6 deletions elements/sifrr-progress-round/src/sifrrprogressround.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ class SifrrProgressRound extends SifrrDom.Element {
return SifrrDom.template(`<style>${style}</style>${template}`);
}

static syncedAttrs() {
return ['progress', 'stroke', 'stroke-width'];
}

onAttributeChange(n, _, v) {
if (n === 'progress' || n === 'stroke' || n === 'stroke-width') this.state = { [n]: Number(v) };
onPropsChange(props) {
if (['progress', 'stroke', 'stroke-width'].filter(p => props.indexOf(p) > -1).length > 0)
this.update();
}
}

Expand Down
8 changes: 4 additions & 4 deletions elements/sifrr-progress-round/src/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
r="28"
fill="none"
stroke="rgba(255, 255, 255, 0.6)"
stroke-width="${this.state['stroke-width']}"
stroke-width="${this['stroke-width']}"
/>
<circle
id="top"
cx="30"
cy="30"
r="28"
fill="none"
stroke="${this.state.stroke}"
stroke-width="${this.state['stroke-width']}"
stroke="${this.stroke}"
stroke-width="${this['stroke-width']}"
stroke-dasharray="188.5"
stroke-dashoffset="${(100 - this.state.progress) / 100 * 188.5}"
stroke-dashoffset="${(100 - this.progress) / 100 * 188.5}"
/>
</svg>
2 changes: 1 addition & 1 deletion elements/sifrr-progress-round/test/browser/state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('state managements', () => {

it('not change state twice on other attribute change', async () => {
await page.$eval('sifrr-progress-round', el =>
el.setAttribute('data-sifrr-state', '{"progress": 55}')
el.setAttribute(':sifrr-state', '{"progress": 55}')
);
assert.equal(await page.$eval('sifrr-progress-round', el => el.state.progress), 55);
});
Expand Down
9 changes: 5 additions & 4 deletions elements/sifrr-shimmer/src/sifrrshimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ function rgbToHsl(r = 0, g = 0, b = 0) {
}

class SifrrShimmer extends SifrrDom.Element {
static syncedAttrs() {
return ['color', 'bg-color', 'fg-color'];
onPropsChange(props) {
if (['color', 'bg-color', 'fg-color'].filter(p => props.indexOf(p) > -1).length > 0)
this.update();
}

static get template() {
return SifrrDom.template(`<style>${properStyle}</style>`);
}

get bgColor() {
getBgColor() {
return this['bg-color'] || this.colora(0.15);
}

get fgColor() {
getFgColor() {
return this['fg-color'] || this.colora(0);
}

Expand Down
6 changes: 3 additions & 3 deletions elements/sifrr-shimmer/src/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
:host {
background: linear-gradient(
to right,
'${this.bgColor}' 4%,
'${this.fgColor}' 25%,
'${this.bgColor}' 36%
'${this.getBgColor()}' 4%,
'${this.getFgColor()}' 25%,
'${this.getBgColor()}' 36%
);
display: inline-block;
animation: shimmer 2.5s linear 0s infinite;
Expand Down
11 changes: 2 additions & 9 deletions elements/sifrr-tab-container/src/sifrrtabcontainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class SifrrTabContainer extends SifrrDom.Element {
return template;
}

static observedAttrs() {
return ['options'];
onPropsChange(props) {
if (props.indexOf('options') > -1) this.refresh();
}

onConnect() {
Expand All @@ -33,13 +33,6 @@ class SifrrTabContainer extends SifrrDom.Element {
this.setScrollEvent();
}

onAttributeChange(n, _, v) {
if (n === 'options') {
this._attrOptions = JSON.parse(v || '{}');
if (this._connected) this.refresh();
}
}

refresh(options) {
this._options = Object.assign(
{
Expand Down
11 changes: 2 additions & 9 deletions elements/sifrr-tab-header/src/sifrrtabheader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class SifrrTabHeader extends SifrrDom.Element {
return template;
}

static observedAttrs() {
return ['options'];
onPropsChange(props) {
if (props.indexOf('options') > -1) this.refresh();
}

onConnect() {
Expand All @@ -29,13 +29,6 @@ class SifrrTabHeader extends SifrrDom.Element {
this.refresh();
}

onAttributeChange(n, _, v) {
if (n === 'options') {
this._attrOptions = JSON.parse(v || '{}');
if (this._connected) this.refresh();
}
}

refresh(options) {
this._options = Object.assign(
{
Expand Down

0 comments on commit b1892b0

Please sign in to comment.