Skip to content

Commit

Permalink
added the "See It Live" section (with demo app in an <iframe>)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinAst committed Mar 19, 2021
1 parent 2b1edf1 commit c0d6755
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 14 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# tw-themes

<p style="text-align: right;">
<p style="text-align: left;">
<img src="docs/img/tw-themes-logo.png"
alt="powerful tailwind color themes (dynamically selectable at run-time)"
width="50%">
Expand Down Expand Up @@ -115,6 +115,16 @@ sections for:
</ul>


<!--- *** Section ************************************************************************* --->
## See It Live

<ul><!--- indentation hack for github - other attempts with style is stripped (be careful with number bullets) --->

Want to see **tw-themes** in action? ... take a peek at the [See It
Live] section _(of the documentation)_.

</ul>

<!--- *** Section ************************************************************************* --->
## Revision History

Expand All @@ -137,4 +147,5 @@ Please refer to the [Revision History] _(found in the documentation)_.
[Getting Started]: https://tw-themes.js.org/start.html
[Concepts]: https://tw-themes.js.org/concepts.html
[API Reference]: https://tw-themes.js.org/api.html
[See It Live]: https://tw-themes.js.org/seeItLive.html
[Revision History]: https://tw-themes.js.org/history.html
7 changes: 7 additions & 0 deletions book.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"intro": "[Introduction](/intro.md)",
"install": "[Install](/install.md)",
"start": "[Getting Started](/start.md)",
"seeItLive": "[See It Live](/seeItLive.md)",
"concepts": "[Concepts](/concepts.md)",

"contextColors": "[Context Colors](/concepts/contextColors.md)",
Expand Down Expand Up @@ -120,6 +121,12 @@
},
"ext": {
"tailwindcss": "[tailwindcss](https://tailwindcss.com/)",
"snfGithub": "[svelte-native-forms](https://github.com/KevinAst/svelte-native-forms)",
"snfDemoApp": "[demo app](https://svelte-native-forms.js.org/app/)",
"snf_colorTheme_js": "[`src/layout/colorTheme.js`](https://github.com/KevinAst/svelte-native-forms/blob/main/src/layout/colorTheme.js)",
"snf_ThemeSelector_svelte": "[`src/layout/ThemeSelector.svelte`](https://github.com/KevinAst/svelte-native-forms/blob/main/src/layout/ThemeSelector.svelte)",
"snf_ThemeInversionSelector_svelte": "[`src/layout/ThemeInversionSelector.svelte`](https://github.com/KevinAst/svelte-native-forms/blob/main/src/layout/ThemeInversionSelector.svelte)",
"snf_tailwind_config_js": "[`tailwind.config.js`](https://github.com/KevinAst/svelte-native-forms/blob/main/tailwind.config.js)",
"KISS": "[KISS Principle](https://en.wikipedia.org/wiki/KISS_principle)",
"cssVars": "[CSS Custom Properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties)",
"svelte": "[Svelte](https://svelte.dev/)",
Expand Down
3 changes: 3 additions & 0 deletions docs/concepts/pullTogether.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ The {{book.api.TwThemes}} object contains functions to:
- auto configure the **tailwind** context colors in
`tailwind.config.js` _(part of the build process)_ ... see:
{{book.api.colorConfig}}

> Want to see **tw-themes** in action? ... take a peek at the
> {{book.guide.seeItLive}} section.
2 changes: 1 addition & 1 deletion docs/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Release | What | *When*

**NOTE**: This release is a **non-breaking change** _(i.e. no API was affected)_.

1. **Docs**: ?? The "See It Live" section was introduced. ?? LINK
1. **Docs**: The {{book.guide.seeItLive}} section was introduced.

1. **Docs**: An improved **tw-themes** logo was introduced.

Expand Down
Binary file added docs/img/snfThemeUIControl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ real support for the dynamics that are needed for this task.
If you are a **tailwind** user _that needs **dynamic color themes**_,
this utility may be just what you are looking for!

> Want to see **tw-themes** in action? ... take a peek at the
> {{book.guide.seeItLive}} section.
<!--- Badges --->
[![NPM Version
Badge](https://img.shields.io/npm/v/tw-themes.svg)](https://www.npmjs.com/package/tw-themes)
Expand Down Expand Up @@ -97,12 +100,12 @@ Using **tw-themes** ...

- {{book.guide.start}} ... _introduction and basic usage patterns_

- {{book.guide.concepts}} ... _basic concepts concepts and terminology_
- {{book.guide.seeItLive}} ... _see a real **tw-themes** app_

- {{book.api.api}} ... _API reference_
- {{book.guide.concepts}} ... _basic concepts concepts and terminology_

- _Misc_ ...
- {{book.api.api}} ... _full API reference_

- {{book.misc.history}} ... _peruse the various revisions of **feature-u**_
- {{book.misc.history}} ... _peruse the various revisions of **feature-u**_

- {{book.misc.LICENSE}} ... _legal stuff_
- {{book.misc.LICENSE}} ... _legal stuff_
190 changes: 190 additions & 0 deletions docs/seeItLive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# See It Live

Want to see a real **tw-themes** app?

{{book.ext.snfGithub}} is the project _where **tw-themes** was
conceived_. It is a {{book.ext.svelte}} utility providing form
validation, and contains a {{book.ext.snfDemoApp}} illustrating
various samples. <mark>Here is a live demo:</mark>

<!-- *** embedded app *** -->
<p align="center">
<iframe name="snfApp"
id="snfApp"
width="700"
height="394"
src="https://svelte-native-forms.js.org/app/"
frameborder="0"></iframe>
</p>

For the purposes of demonstrating **tw-themes**, we are merely focused
on changing the active theme ... _found the upper right dropdown
menu_:

<p style="text-align: center;">
<img class="diagram"
src="img/snfThemeUIControl.png"
alt="Theme Selection Dropdown"
width="30%">
</p>

You can select your "theme color", and toggle "Dark Mode"
... <mark>try it (in the live demo above)</mark>.

From a "theme coding" perspective, there are only a few modules of
interest:

1. {{book.ext.snf_colorTheme_js}}

This is the primary module that promotes our {{book.api.TwThemes}}
object, through the {{book.api.initTwThemes}} invocation, fusing
the relationship between our {{book.api.Schema}} and
{{book.api.Themes}}.

- The {{book.api.Schema}} is defined as follows:

```js
const schema = [
'primaryLight',
'primary',
'primaryDark',

'secondaryLight',
'secondary',
'secondaryDark',

'onLight', // typically black
'onDark', // typically white

'accentBorder', // typically a gray tone (e.g. 'coolGray-600')
// ... used for borders in SideBar/NavBar/Menu/Dialog/etc.

'backdrop', // universal background
// ... can be a gray tone (e.g. 'coolGray-200')
// ... or lighter primary shade (e.g. `${primary}-100`)
// ... lighter that 'primaryLight'
// providing NOT too much of same color
];
```

- Our {{book.api.Themes}} are defined as follows:

```js
const themes = {
'Warm': { contextColors: gen('warmGray', 'amber'), },
'Cool': { contextColors: gen('coolGray', 'orange'), },
'Mono': {
contextColors: {
...gen('coolGray', 'red'), // ... base colors
'primaryLight': 'white', // ... overrides:
'primaryDark': 'black',
'backdrop': 'white',
}
},
'Amber': { contextColors: gen('amber', 'indigo'), },
'Teal': { contextColors: gen('teal', 'rose'), },
'Cyan': { contextColors: gen('cyan', 'orange'), },
'Indigo': { contextColors: gen('indigo', 'amber'), },
};
```

- Notice that we utilize a helper function that generates the
default contextColors _(which can be overridden)_:

```js
function gen(primary, secondary) {
return {
'primaryLight': `${primary}-300`,
'primary': `${primary}-500`,
'primaryDark': `${primary}-900`,

'secondaryLight': `${secondary}-300`,
'secondary': `${secondary}-500`,
'secondaryDark': `${secondary}-900`,

'onLight': 'black',
'onDark': 'white',

'accentBorder': 'coolGray-600',

'backdrop': `${primary}-100`, // or: 'coolGray-200'
};
}
```

- Finally, we invoke {{book.api.initTwThemes}} and promote the
{{book.api.TwThemes}} object through an export.

```js
const initialThemeName = 'Warm'; // AI: ENHANCE TO pull from local storage
const initialInvertShade = true; // ditto
const TwThemes = initTwThemes(schema, themes, initialThemeName, initialInvertShade);
export default TwThemes;
```

1. {{book.ext.snf_ThemeSelector_svelte}}

The `<ThemeSelector>` component is an **extremely simple solution**
to changing the theme. It merely invokes the
{{book.api.activatePriorTheme}} / {{book.api.activateNextTheme}}
functions on the arrow clicks.

While I don't expect you to be a svelte user, the relevant code
snippets are:
```html
<script>
import TwThemes from './colorTheme';
</script>
<span>
<Icon name="arrow_back_ios"
... snip snip
on:click={() => theme = TwThemes.activatePriorTheme()}/>
{theme}
<Icon name="arrow_forward_ios"
... snip snip
on:click={() => theme = TwThemes.activateNextTheme()}/>
</span>
```
**Easy Peasy**!
1. {{book.ext.snf_ThemeInversionSelector_svelte}}
The `<ThemeInversionSelector>` component is an **equally simple
solution** to changing the theme's dark mode.

It merely invokes the {{book.api.toggleInvertShade}} function.

1. {{book.ext.snf_tailwind_config_js}}

Of course, we communicate our {{book.guide.contextColors}} to
**tailwind** through `TwThemes`'s {{book.api.colorConfig}}
function:

**`tailwind.config.js`**
```js
export default {
... snip snip
theme: {
extend: {
colors: TwThemes.colorConfig(),
},
},
... snip snip
};
```

1. Lastly, the **html markup** found throughout the project is
utilizing the context colors defined by our app.

```html
<span class="text-onLight hover:bg-primary hover:text-onDark ... snip snip">
That's All Folks :-)
</span>
```
8 changes: 2 additions & 6 deletions docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ to setup your color themes. This is not so much a reflection of the
**tw-themes** utility, but rather the nature of the beast. **tw-themes** itself
is easy to use, and _simplifies a number of burdensome details_.

> Want to see **tw-themes** in action? Take a peek at my [Svelte
> Native Forms Demo App](https://svelte-native-forms.js.org/app/)
> _([source
> here](https://github.com/KevinAst/svelte-native-forms/tree/main/src))_.
> The theme selection and dark mode controls are in the top-right
> NavBar drop-down.
> Want to see **tw-themes** in action? ... take a peek at the
> {{book.guide.seeItLive}} section.
1. **First**: You must determine the {{book.guide.contextColors}} that
you will use in your application.
Expand Down
6 changes: 5 additions & 1 deletion docs/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

### tw-themes (0.1.0)
* [Install](install.md)
* [Getting Started](start.md)

----
* [Getting Started](start.md)
* [See It Live](seeItLive.md)

----
* [Concepts](concepts.md)
* [Context Colors](concepts/contextColors.md)
* [Themes](concepts/themes.md)
Expand Down Expand Up @@ -39,4 +41,6 @@
* [Revision History](history.md)
* [v0.1.1 (March 18, 2021)](history.md#v0_1_1)
* [v0.1.0 (March 17, 2021)](history.md#v0_1_0)

----
* [MIT License](LICENSE.md)

0 comments on commit c0d6755

Please sign in to comment.