You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lorem ipsum dolor sit amet, consectetur adipiscing elit. **Pellentesque** euismod, nibh ac aliquam aliquam, dui nulla ultrices erat, sit amet dictum nisl ex id nunc. Sed malesuada, orci vitae tempus euismod, nunc erat semper nisi, in aliquet nibh nisl eget nulla. Donec eget ipsum vitae nibh blandit consequat. Donec facilisis, nibh id aliquam fermentum, mi lorem molestie nisl, id posuere nisi nisi at nulla.
19
18
20
-
It can be a somewhat daunting task trying to get a handle on _AstroWind_ internals, and particularly various points of usage.
19
+
Duis euismod, nulla sit amet mattis euismod, nibh nunc rhoncus nibh, id interdum nunc nisl id lorem. Donec id nunc quis nulla aliquam cursus. Integer vitae nunc nunc. Sed sed nulla vitae nibh interdum gravida. Sed a nunc nibh.
21
20
22
-
This page outlines and clarifies some of the techniques found in _AstroWind_. Use it as a guide for further modification, or an instructional for techniques to use in your own endeavors.
21
+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer euismod, nunc eu lobortis mattis, lectus sem sagittis nunc, id laoreet nunc metus id lectus. Sed consectetur, urna at euismod consectetur, nunc nisi bibendum nibh, ut rhoncus nibh nunc vel mi.
23
22
24
-
## Styling
23
+
Nam eget nunc massa. Nulla facilisi. Sed a ligula vel nunc porta sollicitudin. **Pellentesque** vel mauris vitae nibh varius feugiat. Fusce eget nunc id ligula bibendum venenatis.
25
24
26
-
As the name suggests, _AstroWind_ relies on _TailWind_ for styling. Furthermore, _AstroWind_ defines custom low level style settings which are incorporated into _TailWind_ seamlessly, and which provides consistency for higher level styling constructs, as well as enabling dark mode.
25
+
### Nisi rutrum eros euismod
27
26
28
-
The styling mechanism consists of the following files (all paths are prefixed with `/src/` ):
27
+
Maecenas eget justo sed nibh consequat vulputate. Sed euismod neque vel nunc rhoncus, nec tincidunt nisl laoreet. Sed euismod justo id nulla varius, id cursus nibh tincidunt. Sed euismod est et nunc consectetur, id tempus nibh euismod.
29
28
30
-
<DListItemdt="assets/styles/tailwind.css">
31
-
This file is essentially an extension of _TailWind's_ base.css. High-level component styles are defined here. Note
32
-
also styling on elements selected by 'attribute' selectors at the bottom of the files, particularly those selected by
33
-
'data' attributes.
34
-
</DListItem>
35
-
<DListItemdt="components/CustomStyles.astro">
36
-
Defines custom colors and fonts. For these to take effect in the 'base.css' file, they need to be loaded in the html
37
-
header section. See next.
38
-
</DListItem>
39
-
<DListItemdt="layouts/Layout.astro">
40
-
This layout is used for all of the pages rendered by _AstroWind_. The contents of _tailwind.css_ and
41
-
_CustomStyles.astro_ component, described above, is injected into the html header.
42
-
</DListItem>
29
+
In hac habitasse platea dictumst. Integer euismod, nunc eu lobortis mattis, lectus sem sagittis nunc, id laoreet nunc metus id lectus. Aenean sagittis, ligula vel blandit aliquam, nisl nunc euismod elit, nec tincidunt lectus nunc vitae nunc. Sed euismod justo id nulla varius, id cursus nibh tincidunt. Sed euismod est et nunc consectetur, id tempus nibh euismod.
43
30
44
-
### Dark Mode
31
+
### Nisi rutrum eros euismod
45
32
46
-
_Dark Mode_ is triggered by the little 'sunlight' icon:<ToggleTheme/>in the page header. It is defined in the _components/common/ToggleTheme.astro_, but the event is attached and the action defined in _components/common/BasicScripts.astro_ in the following snippet:
33
+
Quisque euismod lectus ac nunc dictum, id eleifend nunc euismod. Sed euismod, nunc eu lobortis mattis, lectus sem sagittis nunc, id laoreet nunc metus id lectus. Sed consectetur, urna at euismod consectetur, nunc nisi bibendum nibh, ut rhoncus nibh nunc vel mi.
47
34
48
-
```javascript
49
-
attachEvent('[data-aw-toggle-color-scheme]', 'click', function () {
Note that this is a client event. _BasicScripts.astro_ defines several other client-side functionality as well as this one.
59
-
60
-
## Advanced Slot Usage
61
-
62
-
_slots_ are part of the component implementation, which is a common concept among many frameworks, including _Astrojs_. The typical slot definition in a component looks like this:
63
-
64
-
```astro
65
-
---
66
-
// (file: MyComponent.astro)
67
-
const { title } = Astro.props;
68
-
export interface Props {
69
-
title: string;
70
-
}
71
-
---
72
-
73
-
<div>
74
-
<h2>{title}</h2>
75
-
<slot />
76
-
<!-- slot contents injected here -->
77
-
<div></div>
78
-
</div>
79
-
```
80
-
81
-
And in usage elsewhere:
82
-
83
-
```astro
84
-
import MyComponent from "~/components/MyComponent"; ...
85
-
<MyComponent someArg="A Slot example">
86
-
<p>This content will be displayed in the slot</p>
87
-
</MyComponent>
88
-
```
89
-
90
-
### Alternate usage
91
-
92
-
There's another way we can use slots, useful particularly when a component can have markdown content is as follows (study carefully...):
Notice there is no slot definition in the html portion of the component. Instead, what we do is have _Astro_ render the slot content (here, the 'default' content, but you can also render named slots) into a variable, and then use that content in a _div_ (for instance).
# Using the above component in a .mdx file (that can take components)
124
-
125
-
{''}
126
-
127
-
<MyComponenttitle="This is a slot implementor">### Here is some markdown content - With a bullet item.</MyComponent>
128
-
```
129
-
130
-
_MyComponent_ renders the markdown to html and then injects it into the div.
131
-
132
-
This actually has a big advantage -- consider that with the normal usage you don't have access to the slot contents: _Astro_ just plops the content into the _<slot/>_ tag. Using this method, however, allows you to access the content and further manipulate it before it gets inserted into the html.
133
-
134
-
This allows a great deal of flexibility in component design.
135
-
136
-
### Yet Another Step
137
-
138
-
Now, we get to the techniques used in _AstroWind_, we'll use the _pages/index.astro_ file to illustrate.
139
-
140
-
You'll note that the index file imports a lot of components, each one roughly analogous to a panel in the index page. Each of these components, in turn, is instantiated sequentially throughout the page. But, you'll notice that some of them use this kind of construct (we'll use the last section, _CallToAction_, as it is most illustrative of the technique):
This argument is actually being passed a javascript object -- not a string. (However, in the TS definition, it could
165
-
be a string...)
166
-
</DListItem>
167
-
<DListItemdt="There are several <em>Fragment</em> children">
168
-
Furthermore, these <Fragment/> elements each have a _slot="(value)"_ specifier.
169
-
</DListItem>
170
-
171
-
The latter seems odd, because <Fragment/> is a built-in component over which you have no control, and doesn't have a provision for rendering slots, <em>per se</em>.
172
-
173
-
The answer lies in a paragraph in the _Astro_ docs, slots section, which states:
174
-
175
-
> Use a `slot="my-slot"` attribute on the child element that you want to pass through to a matching slot `name="my-slot" />` placeholder in your component.
176
-
177
-
That's pretty concise and a bit of a head-scratcher to read, but basically what it says is that:
178
-
179
-
1. Given a component that defines a slot:
180
-
1. you can reference a slot from a child element of that component and,
181
-
1. provide content to the parent component's slot from the child by naming the slot in the child with a `slot="<slot-name>"` property assignment, where the _slot-name_ is the parent's slot.
182
-
183
-
So, in the example above, the _CallToAction_ component defines the _subtitle_ slot, and the following _<Fragment slot="subtitle">_ populates the slot with the following content:
184
-
185
-
```astro
186
-
<Fragment slot="subtitle">
187
-
Be very surprised by these huge fake numbers you are seeing on this page. <br class="hidden md:inline" />Don't waste
188
-
more time! :P
189
-
</Fragment>
190
-
```
191
-
192
-
And, the _CallToAction_ component defines and renders it thusly:
Notice first that _subtitle_ is defined as a prop/argument, but it's being processed as a slot. Interestingly, prop args and slots seem to be somewhat interchangeable: if the subtitle was just a string, it would simply take that assignment. The main difference is that if you render them independently, you have to call the render with an _await_ modifier.
35
+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed euismod est et nunc consectetur, id tempus nibh euismod.
0 commit comments