Skip to content

Commit 5798712

Browse files
committed
fixes #602 - extend css-parts to nested components
1 parent fd83f5c commit 5798712

File tree

8 files changed

+74
-30
lines changed

8 files changed

+74
-30
lines changed

docs/css-parts.html

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,41 @@ <h2>CSS Parts</h2>
191191
</code>
192192
</pre>
193193
</p>
194-
<h2>Limitation</h2>
195-
<p>RapiDoc web Component is made up of smaller web components, below is RapiDoc component composition structure
196-
<br/>
197-
At the moment CSS Parts can target only those HTML content which directly fall under <span class="mono bold blue"> &lt;rapi-doc&gt;</span> element.
198-
<br/>
199-
HTML elements under <span class="mono bold"> &lt;api-request&gt;, &lt;api-response&gt; &lt;schema-tree&gt; and &lt;schema-table&gt; cannot be targeted for styling</span>
200-
</p>
201-
<pre>
202-
- rapi-doc
203-
- api-request
204-
- schema-tree
205-
- schema-table
206-
- api-response
207-
- schema-tree
208-
- schema-table
209-
</pre>
210194

195+
<p>
196+
<span>
197+
Another Example to change the button styles
198+
| <a href="./examples-theme/cssparts-btn.html" target="_blank"> Demo</a>
199+
</span>
200+
<pre class="shadow1 code-block" style="width:730px">
201+
<code class="language-html">
202+
&lt;html&gt;
203+
...
204+
&lt;style&gt;
205+
rapi-doc::part(btn){ border-radius: 15px; }
206+
rapi-doc::part(btn-try) {
207+
background-color: yellow;
208+
color: #333;
209+
border-color: yellow;
210+
}
211+
rapi-doc::part(btn-selected-response-status) {
212+
background-color: yellow;
213+
color: #333;
214+
border-color: yellow;
215+
}
216+
&lt;/style&gt;
217+
&lt;rapi-doc spec-url = "https://petstore.swagger.io/v2/swagger.json"
218+
show-header = "false"
219+
nav-bg-color = "#423368"
220+
primary-color ="#df75c4"
221+
bg-color = "#fae4f5"
222+
&gt; &lt;/rapi-doc&gt;
223+
...
224+
&lt;/html&gt;
225+
</code>
226+
</pre>
227+
228+
</p>
211229
<p>
212230
Following are the list of <span class="mono bold blue">css ::part</span> provided by rapidoc. The names of these parts should be self explenatory
213231
<table class="m-table">
@@ -230,7 +248,7 @@ <h2>Limitation</h2>
230248
<tr> <td class="blue" style="border:none">Buttons</td></tr>
231249
<tr>
232250
<td class="mono">
233-
btn, btn-fill, btn-outline, btn-search
251+
btn, btn-fill, btn-outline, btn-search, btn-try, btn-fill, btn-clear, btn-copy, btn-clear-resp,
234252
</td>
235253
</tr>
236254

@@ -241,10 +259,17 @@ <h2>Limitation</h2>
241259
</td>
242260
</tr>
243261

262+
<tr> <td class="blue" style="border:none">Inputs</td></tr>
263+
<tr>
264+
<td class="mono">
265+
textbox, textbox-param, textarea, textarea-param, file-input
266+
</td>
267+
</tr>
268+
244269
<tr><td class="blue" style="border:none">Anchors</td></tr>
245270
<tr>
246271
<td class="mono">
247-
anchor, anchor-overview
272+
anchor, anchor-overview, anchor-param-example
248273
</td>
249274
</tr>
250275
</table>

docs/examples-theme/cssparts-btn1.html renamed to docs/examples-theme/cssparts-btn.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
<script type="module" src="../rapidoc-min.js"></script>
1717
<style>
1818
rapi-doc::part(btn){ border-radius: 15px; }
19+
rapi-doc::part(btn-try) {
20+
background-color: yellow;
21+
color: #333;
22+
border-color: yellow;
23+
}
24+
rapi-doc::part(btn-selected-response-status) {
25+
background-color: yellow;
26+
color: #333;
27+
border-color: yellow;
28+
}
1929
</style>
2030
</head>
2131
<body>

src/components/api-request.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ export default class ApiRequest extends LitElement {
912912
<div class="row" style="font-size:var(--font-size-small); margin:5px 0">
913913
<div class="response-message ${this.responseStatus}">Response Status: ${this.responseMessage}</div>
914914
<div style="flex:1"></div>
915-
<button class="m-btn" part="btn btn-outline" @click="${this.clearResponseData}">CLEAR RESPONSE</button>
915+
<button class="m-btn" part="btn btn-outline btn-clear-response" @click="${this.clearResponseData}">CLEAR RESPONSE</button>
916916
</div>
917917
<div class="tab-panel col" style="border-width:0 0 1px 0;">
918918
<div id="tab_buttons" class="tab-buttons row" @click="${(e) => {
@@ -1005,15 +1005,15 @@ export default class ApiRequest extends LitElement {
10051005
${
10061006
this.parameters.length > 0 || this.request_body
10071007
? html`
1008-
<button class="m-btn thin-border" part="btn btn-outline" style="margin-right:5px;" @click="${this.onFillRequestData}" title="Fills with example data (if provided)">
1008+
<button class="m-btn thin-border" part="btn btn-outline btn-fill" style="margin-right:5px;" @click="${this.onFillRequestData}" title="Fills with example data (if provided)">
10091009
FILL EXAMPLE
10101010
</button>
1011-
<button class="m-btn thin-border" part="btn btn-outline" style="margin-right:5px;" @click="${this.onClearRequestData}">
1011+
<button class="m-btn thin-border" part="btn btn-outline btn-clear" style="margin-right:5px;" @click="${this.onClearRequestData}">
10121012
CLEAR
10131013
</button>`
10141014
: ''
10151015
}
1016-
<button class="m-btn primary thin-border" part="btn btn-fill btn-try" @click="${this.onTryClick}">TRY</button>
1016+
<button class="m-btn primary thin-border" part="btn btn-try" @click="${this.onTryClick}">TRY</button>
10171017
</div>
10181018
${this.responseMessage === '' ? '' : this.apiResponseTabTemplate()}
10191019
`;

src/components/api-response.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export default class ApiResponse extends LitElement {
154154
}
155155
}}"
156156
class='m-btn small ${this.selectedStatus === respStatus ? 'primary' : ''}'
157-
part="btn--resp ${this.selectedStatus === respStatus ? 'btn-fill--resp' : 'btn-outline--resp'} btn-response-status"
157+
part="btn ${this.selectedStatus === respStatus ? 'btn-response-status btn-selected-response-status' : ' btn-response-status'}"
158158
style='margin: 8px 4px 0 0'
159159
>
160160
${respStatus}
@@ -258,6 +258,7 @@ export default class ApiResponse extends LitElement {
258258
render-style = '${this.renderStyle}'
259259
.data="${mimeRespDetails.examples[0].exampleValue}"
260260
class = 'example-panel ${this.renderStyle === 'read' ? 'border pad-8-16' : 'border-top pad-top-8'}'
261+
exportparts = "btn:btn, btn-fill:btn-fill, btn-copy:btn-copy"
261262
></json-tree>`
262263
: html`
263264
${mimeRespDetails.examples[0].exampleSummary && mimeRespDetails.examples[0].exampleSummary.length > 80 ? html`<div style="padding: 4px 0"> ${mimeRespDetails.examples[0].exampleSummary} </div>` : ''}
@@ -281,6 +282,7 @@ export default class ApiResponse extends LitElement {
281282
<json-tree
282283
render-style = '${this.renderStyle}'
283284
.data = '${v.exampleValue}'
285+
exportparts = "btn:btn, btn-fill:btn-fill, btn-copy:btn-copy"
284286
></json-tree>`
285287
: html`<pre>${v.exampleValue}</pre>`
286288
}

src/components/json-tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class JsonTree extends LitElement {
7878
return html`
7979
<div class = "json-tree" >
8080
<div class='toolbar'>
81-
<button class="toolbar-btn" part="btn btn-fill" @click='${(e) => { copyToClipboard(JSON.stringify(this.data, null, 2), e); }}'> Copy </button>
81+
<button class="toolbar-btn" part="btn btn-fill btn-copy" @click='${(e) => { copyToClipboard(JSON.stringify(this.data, null, 2), e); }}'> Copy </button>
8282
</div>
8383
${this.generateTree(this.data, true)}
8484
</div>

src/templates/callback-template.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export default function callbackTemplate(callbacks) {
3838
allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}",
3939
schema-hide-read-only = "${this.schemaHideReadOnly}"
4040
fetch-credentials = "${this.fetchCredentials}"
41-
exportparts="btn btn-fill btn-outline btn-try"
41+
exportparts = "btn:btn, btn-fill:btn-fill, btn-outline:btn-outline, btn-try:btn-try, btn-clear:btn-clear, btn-clear-resp:btn-clear-resp,
42+
file-input:file-input, textbox:textbox, textbox-param:textbox-param, textarea:textarea, textarea-param:textarea-param,
43+
anchor:anchor, anchor-param-example:anchor-param-example"
4244
> </api-request>
4345
4446
<api-response
@@ -52,7 +54,7 @@ export default function callbackTemplate(callbacks) {
5254
schema-expand-level = "${this.schemaExpandLevel}"
5355
schema-description-expanded = "${this.schemaDescriptionExpanded}"
5456
allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
55-
exportparts = "btn--resp btn-fill--resp btn-outline--resp"
57+
exportparts = "btn:btn, btn-response-status:btn-response-status, btn-selected-response-status:btn-selected-response-status, btn-fill:btn-fill, btn-copy:btn-copy"
5658
> </api-response>
5759
</div>
5860
</div>

src/templates/endpoint-template.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ function endpointBodyTemplate(path) {
137137
allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
138138
schema-hide-read-only = "${this.schemaHideReadOnly}"
139139
fetch-credentials = "${this.fetchCredentials}"
140-
exportparts="btn btn-fill btn-outline btn-try"
140+
exportparts = "btn:btn, btn-fill:btn-fill, btn-outline:btn-outline, btn-try:btn-try, btn-clear:btn-clear, btn-clear-resp:btn-clear-resp,
141+
file-input:file-input, textbox:textbox, textbox-param:textbox-param, textarea:textarea, textarea-param:textarea-param,
142+
anchor:anchor, anchor-param-example:anchor-param-example"
141143
> </api-request>
142144
143145
${path.callbacks ? callbackTemplate.call(this, path.callbacks) : ''}
@@ -155,7 +157,8 @@ function endpointBodyTemplate(path) {
155157
allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
156158
schema-hide-write-only = "${this.schemaHideWriteOnly}"
157159
selected-status = "${Object.keys(path.responses || {})[0] || ''}"
158-
exportparts = "btn--resp btn-fill--resp btn-outline--resp"
160+
exportparts =
161+
"btn:btn, btn-fill:btn-fill, btn-outline:btn-outline, btn-try:btn-try, file-input:file-input, textbox:textbox, textbox-param:textbox-param, textarea:textarea, textarea-param:textarea-param, anchor:anchor, anchor-param-example:anchor-param-example, btn-clear-resp:btn-clear-resp"
159162
> </api-response>
160163
</div>
161164
</div>`;

src/templates/expanded-endpoint-template.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ export function expandedEndpointBodyTemplate(path, tagName = '') {
8989
allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
9090
schema-hide-read-only = "${this.schemaHideReadOnly}"
9191
fetch-credentials = "${this.fetchCredentials}"
92-
exportparts = "btn btn-fill btn-outline btn-try"
92+
exportparts = "btn:btn, btn-fill:btn-fill, btn-outline:btn-outline, btn-try:btn-try, btn-clear:btn-clear, btn-clear-resp:btn-clear-resp,
93+
file-input:file-input, textbox:textbox, textbox-param:textbox-param, textarea:textarea, textarea-param:textarea-param,
94+
anchor:anchor, anchor-param-example:anchor-param-example"
9395
> </api-request>
9496
9597
${path.callbacks ? callbackTemplate.call(this, path.callbacks) : ''}
@@ -106,7 +108,7 @@ export function expandedEndpointBodyTemplate(path, tagName = '') {
106108
allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
107109
schema-hide-write-only = "${this.schemaHideWriteOnly}"
108110
selected-status = "${Object.keys(path.responses || {})[0] || ''}"
109-
exportparts = "btn--resp btn-fill--resp btn-outline--resp"
111+
exportparts = "btn:btn, btn-response-status:btn-response-status, btn-selected-response-status:btn-selected-response-status, btn-fill:btn-fill, btn-copy:btn-copy"
110112
> </api-response>
111113
</div>
112114
</div>

0 commit comments

Comments
 (0)