Skip to content

Commit

Permalink
v0.2.1
Browse files Browse the repository at this point in the history
Closes #18
  • Loading branch information
barvian committed May 9, 2024
1 parent 4ee9701 commit 9003035
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 29 deletions.
2 changes: 1 addition & 1 deletion plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fluid-tailwind",
"version": "0.2.0",
"version": "0.2.1",
"author": "Maxwell Barvian",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
59 changes: 32 additions & 27 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,35 +113,9 @@ const fluid = plugin.withOptions((options: PluginOptions = {}) => (api: PluginAP
const context = getContext(theme, options)
const { screens, containers } = context

// Add fluid versions for enabled core plugins
const fluidCoreAPI = getFluidAPI(api, context, {
// Filter out fontSize plugin
filter: (utils, options) => !utils.includes('text') || !options?.type?.includes('length')
})
Object.entries(corePlugins).forEach(([name, corePlugin]) => {
if (!corePluginEnabled(name)) return
corePlugin(fluidCoreAPI)
})

// Add fluid versions of external plugins
const fluidPluginAPI = getFluidAPI(api, context)
const plugins = config('plugins') as (Function | Plugin)[]
plugins.forEach((plug, i) => {
if (typeof plug === 'function') {
// It's a plugin.withOptions, but wasn't passed options so try executing it
// with no arguments:
try {
(plug() as Plugin).handler(fluidPluginAPI)
} catch (e) {
log.warn('fluid-tailwind', `Could not add fluid version of \`plugins[${i}]\``)
}
} else {
plug.handler(fluidPluginAPI)
}
})

// Add new fluid text utility to handle potentially complex theme values
// ---
// This has to be first so that utilities like ~leading (from corePlugins) can override it

type Values<Type> = Type extends KeyValuePair<any, infer Item> ? Item : never
type FontSize = Values<ThemeConfig['fontSize']>
Expand Down Expand Up @@ -238,6 +212,37 @@ const fluid = plugin.withOptions((options: PluginOptions = {}) => (api: PluginAP
}
)

// Add fluid versions for enabled core plugins
// ---

const fluidCoreAPI = getFluidAPI(api, context, {
// Filter out fontSize plugin
filter: (utils, options) => !utils.includes('text') || !options?.type?.includes('length')
})
Object.entries(corePlugins).forEach(([name, corePlugin]) => {
if (!corePluginEnabled(name)) return
corePlugin(fluidCoreAPI)
})

// Add fluid versions of external plugins
// ---

const fluidPluginAPI = getFluidAPI(api, context)
const plugins = config('plugins') as (Function | Plugin)[]
plugins.forEach((plug, i) => {
if (typeof plug === 'function') {
// It's a plugin.withOptions, but wasn't passed options so try executing it
// with no arguments:
try {
;(plug() as Plugin).handler(fluidPluginAPI)
} catch (e) {
log.warn('fluid-tailwind', `Could not add fluid version of \`plugins[${i}]\``)
}
} else {
plug.handler(fluidPluginAPI)
}
})

// Screen variants
// ---

Expand Down
28 changes: 28 additions & 0 deletions plugin/tests/text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,34 @@ it(`applies consistent line height`, async () => {
`)
})

it(`can be overridden by ~leading`, async () => {
const result = await run({
content: [
{
raw: html`<div class="~text-sm/lg ~leading-3/4"></div>`
}
]
})
expect(result.css).toMatchFormattedCss(css`
.\~text-sm\/lg {
font-size: clamp(0.875rem, 0.696rem + 0.446vw, 1.125rem)
/* fluid type from 0.875rem at 40rem to 1.125rem at 96rem */;
line-height: clamp(
1.25rem,
0.89rem + 0.89vw,
1.75rem
); /* fluid from 1.25rem at 40rem to 1.75rem at 96rem */
}
.\~leading-3\/4 {
line-height: clamp(
0.75rem,
0.57rem + 0.45vw,
1rem
); /* fluid from 0.75rem at 40rem to 1rem at 96rem */
}
`)
})

it(`fails for inconsistent line height`, async () => {
const result = await run({
content: [
Expand Down
2 changes: 1 addition & 1 deletion site/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Resizer from '/components/Resizer.svelte'

* Supports **every utility** out of the box (including plugins)
* Full **Intellisense** support
* Ensures all fluid type meets [accessibility requirements](#fluid-type-accessibility-errors)
* Ensures fluid type meets [accessibility requirements](#fluid-type-accessibility-errors)
* **Flexible** enough to handle advanced use cases


Expand Down

0 comments on commit 9003035

Please sign in to comment.