Skip to content

Commit 92c1ac9

Browse files
committed
Improvements for example view
- Added a frame around the example box and an optional title displayed within the frame
1 parent a4e6792 commit 92c1ac9

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

functions/Cursor/isCursorShowing.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ client:
3434
- path: 'examples/isCursorShowing-3.lua'
3535
description: |
3636
This example creates a function to set the state of the [player](/player)'s cursor using the [showCursor](/showCursor) function.
37+
exampleTitle: 'Toggle Cursor'
3738
- path: 'examples/isCursorShowing-4.lua'
3839
description: |
3940
If you are already advanced in scripting, using this code is recommended, as it is much more compact:
4041
append: true
42+
exampleTitle: 'Toggle Cursor'
4143
- path: 'examples/isCursorShowing-5.lua'
4244
description: |
4345
This example creates a function that allows the [player](/player) to change the state of the cursor using the [showCursor](/showCursor) and [bindKey](/bindKey) functions.
46+
exampleTitle: 'Toggle Cursor by binded key'
4447
- path: 'examples/isCursorShowing-6.lua'
4548
description: |
4649
If you are already advanced in scripting, using this code is recommended, as it is much more compact:
4750
append: true
51+
exampleTitle: 'Toggle Cursor by binded key'

schemas/common-defs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ $defs:
117117
type: boolean
118118
default: false
119119
description: If set to true, this example will be appended to the previous example.
120+
exampleTitle:
121+
type: string
122+
description: Optional title displayed in the frame around the example.
120123

121124
see_also:
122125
type: array

web/src/components/CodeExamplesSection.astro

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface CodeExample {
77
description?: string;
88
luaCode: string;
99
side: string;
10+
exampleTitle?: string;
1011
}
1112
1213
export interface Props {
@@ -38,10 +39,23 @@ const { codeExamples } = Astro.props;
3839
)}
3940

4041
{codeExamples.map((example, index) => (
41-
<div class="tab-content" data-tab={index} style={{ display: index === 0 ? 'block' : 'none' }}>
42-
{example.description && <Fragment set:html={marked(example.description)} />}
43-
<div class="code-example">
44-
<Code code={example.luaCode} lang="lua" />
42+
<div
43+
class="tab-content"
44+
data-tab={index}
45+
style={{
46+
display: index === 0 ? 'flex' : 'none',
47+
flexDirection: 'column',
48+
border: `2px solid var(--color-type-${example.side}-background-high)`
49+
}}
50+
>
51+
<div class={`tab-header side-${example.side} active`}>
52+
<strong>{example.side}</strong> {example.exampleTitle && ` - ${example.exampleTitle}`}
53+
</div>
54+
<div class="tab-body">
55+
{example.description && <Fragment set:html={marked(example.description)} />}
56+
<div class="code-example">
57+
<Code code={example.luaCode} lang="lua" />
58+
</div>
4559
</div>
4660
</div>
4761
))}
@@ -77,6 +91,25 @@ const { codeExamples } = Astro.props;
7791
font-weight: bold;
7892
}
7993

94+
.tab-header {
95+
padding: 0.5rem 1rem;
96+
color: var(--sl-color-text);
97+
text-transform: capitalize;
98+
}
99+
100+
.tab-body {
101+
margin: 0;
102+
padding: 1rem;
103+
color: var(--sl-color-text);
104+
}
105+
106+
.tab-content {
107+
display: flex;
108+
flex-direction: column;
109+
background-color: var(--sl-color-bg-nav);
110+
box-shadow: 0.2rem 0.2rem 0.2rem #0000005b;
111+
}
112+
80113
.side-client {
81114
background-color: var(--color-type-client-background);
82115
border-color: var(--color-type-client);
@@ -103,12 +136,6 @@ const { codeExamples } = Astro.props;
103136
.side-shared.active {
104137
background-color: var(--color-type-shared-background-high);
105138
}
106-
107-
.tab-content {
108-
background-color: var(--sl-color-bg-nav);
109-
padding: 1rem;
110-
box-shadow: var(--ec-frm-frameBoxShdCssVal);
111-
}
112139
</style>
113140

114141
<script>

0 commit comments

Comments
 (0)