Skip to content

Commit 28a8441

Browse files
committed
feat(popover slot): create it so consumers can add rb-popover and not worry about styling
Also update code to accommodate changes in rb-base v0.0.7.
1 parent 8801766 commit 28a8441

File tree

9 files changed

+59
-30
lines changed

9 files changed

+59
-30
lines changed

rapid-build.cson

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ common:
1414
from:
1515
minFile:
1616
scripts: [
17-
'scripts/!(rb-*.js)'
17+
'scripts/**/*.js'
1818
]
1919

2020
extra:

src/client/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"flat": true,
3939
"dependencies": {
4040
"@rapid-build-ui/form-control": "^0.0.5",
41-
"@rapid-build-ui/rb-base": "^0.0.6"
41+
"@rapid-build-ui/rb-base": "^0.0.6",
42+
"@rapid-build-ui/rb-popover": "^0.0.13"
4243
}
4344
}

src/client/scripts/rb-checkbox.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
/**************
22
* RB-CHECKBOX
33
**************/
4-
import { props, html, RbBase } from '../../rb-base/scripts/rb-base.js';
5-
import FormControl from '../../form-control/scripts/form-control.js';
6-
import Type from '../../rb-base/scripts/type-service.js';
7-
import template from '../views/rb-checkbox.html';
4+
import { RbBase, props, html } from '../../rb-base/scripts/rb-base.js';
5+
import FormControl from '../../form-control/scripts/form-control.js';
6+
import Type from '../../rb-base/scripts/public/services/type.js';
7+
import template from '../views/rb-checkbox.html';
8+
import '../../rb-popover/scripts/rb-popover.js';
89

910
export class RbCheckbox extends FormControl(RbBase()) {
10-
11+
/* Lifecycle
12+
************/
1113
constructor() {
1214
super();
1315
this.state = {
16+
...super.state,
1417
value: undefined
1518
}
1619
}
17-
/* Lifecycle
18-
************/
1920
viewReady() { // :void
2021
super.viewReady && super.viewReady();
2122
Object.assign(this.rb.elms, {
2223
focusElm: this.shadowRoot.querySelector('.sublabel'),
2324
formControl: this.shadowRoot.querySelector('input')
2425
});
26+
this._initSlotStates(); // see rb-base: private/mixins/slot.js
2527
}
2628

2729
/* Properties
@@ -113,7 +115,7 @@ export class RbCheckbox extends FormControl(RbBase()) {
113115

114116
/* Template
115117
***********/
116-
render({ props }) { // :string
118+
render({ props, state }) { // :string
117119
return html template;
118120
}
119121
}

src/client/styles/layout/host.scss

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*******/
44
:host {
55
all: initial; // reset all styles first
6-
contain: layout style; // paint cuts off the label above
6+
// paint cuts off the label above
7+
// layout prevents popover from being over everything
8+
contain: style;
79
}
810

911
:host {

src/client/styles/layout/labels.scss

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* LABEL
33
********/
44
.label {
5+
display: flex;
56
margin-bottom: 12px;
67
cursor: text;
78
}

src/client/styles/layout/popover.scss

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/***************
2+
* POPOVER SLOT
3+
***************/
4+
.with-label ::slotted([slot="popover"]) {
5+
position: relative;
6+
top: .5px;
7+
left: -1px;
8+
margin-right: 3px;
9+
}

src/client/styles/rb-checkbox.scss

+13-12
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77

88
/* Layout
99
*********/
10-
@import 'layout/host.scss';
11-
@import 'layout/root.scss';
12-
@import 'layout/labels.scss';
13-
@import 'layout/checkbox.scss';
14-
@import 'layout/subtext.scss';
15-
@import 'layout/options.scss';
10+
@import 'layout/host.scss';
11+
@import 'layout/root.scss';
12+
@import 'layout/labels.scss';
13+
@import 'layout/popover.scss';
14+
@import 'layout/checkbox.scss';
15+
@import 'layout/subtext.scss';
16+
@import 'layout/options.scss';
1617

17-
/* Style
18-
********/
19-
@import 'style/variables.scss';
20-
@import 'style/borders.scss';
21-
@import 'style/colors.scss';
22-
@import 'style/fonts.scss';
18+
/* Style
19+
********/
20+
@import 'style/variables.scss';
21+
@import 'style/borders.scss';
22+
@import 'style/colors.scss';
23+
@import 'style/fonts.scss';
2324

2425
/* Load Last!
2526
*************/

src/client/styles/style/colors.scss

+3
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
.label, .subtext, .sublabel {
2424
color: mapGet($formControlColors, text, invalid, default);
2525
}
26+
::slotted([slot="popover"]) {
27+
--rb-popover-default-trigger-color: mapGet($formControlColors, text, invalid, default);
28+
}
2629
}
2730
}

src/client/views/rb-checkbox.html

+17-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22
?disabled="${props.disabled}"
33
class="
44
form-control
5-
${props.inline ? 'inline' : ''}
6-
${props.horizontal ? 'horizontal' : ''}
75
${props.right ? 'right' : ''}
6+
${props.label && 'with-label'}
7+
${props.inline ? 'inline' : ''}
88
${props._valid ? 'valid' : 'invalid'}
9+
${props.horizontal ? 'horizontal' : ''}
10+
${state.slots.popover ? 'with-popover' : ''}
911
">
10-
11-
${props.label
12-
? html`<label class="label">${props.label}</label>`
13-
: null
12+
${props.label || state.slots.popover
13+
? html`
14+
<div class="label">
15+
${state.slots.popover
16+
? html`<slot name="popover"></slot>`
17+
: null
18+
}
19+
${props.label
20+
? html`<label>${props.label}</label>`
21+
: null
22+
}
23+
</div>
24+
`: null
1425
}
15-
1626
<label
1727
tabindex="${props.disabled ? -1 : 0}"
1828
class="sublabel ${!!props.value ? 'active' : ''}"

0 commit comments

Comments
 (0)