Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: prepare for launch #44

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
952a4b8
chore: run tailwind upgrade
mehdibha Nov 22, 2024
4759c10
chore: we're getting there
mehdibha Nov 22, 2024
aab0de9
fix: format
mehdibha Nov 22, 2024
2a6c2dc
fix: minor fixes
mehdibha Nov 22, 2024
4cc5365
fix: other fixes
mehdibha Nov 22, 2024
f194cee
chore: everything is working*
mehdibha Dec 1, 2024
b5fda69
fix: format
mehdibha Dec 1, 2024
f2a1be4
fix: minor fixes
mehdibha Dec 2, 2024
86e5a24
fix: format
mehdibha Dec 2, 2024
dabc983
refactor: new architecture
mehdibha Dec 3, 2024
184d126
chore: update imports
mehdibha Dec 3, 2024
eea2b7f
chore: update imports
mehdibha Dec 3, 2024
becc401
chore: remove old registry
mehdibha Dec 3, 2024
ccbb99a
chore update demos import
mehdibha Dec 3, 2024
e209e5a
refactor: refactor demos
mehdibha Dec 3, 2024
b223949
fix: format
mehdibha Dec 3, 2024
219b473
chore: clean up
mehdibha Dec 3, 2024
b88705d
fix: add missing demos
mehdibha Dec 3, 2024
ceeb460
fix: format
mehdibha Dec 3, 2024
ac6125b
fix: missing demos
mehdibha Dec 3, 2024
a7ff28c
chore: clean up
mehdibha Dec 5, 2024
9a36195
refactor: new build-registry structure
mehdibha Dec 5, 2024
5188a7f
chore: we're getting there
mehdibha Dec 7, 2024
7cf7e3d
chore: we're getting there
mehdibha Dec 7, 2024
979975b
chore: will be back
mehdibha Dec 8, 2024
fe72d73
chore: update dynamic components
mehdibha Dec 10, 2024
12db22c
refactor: clean up
mehdibha Dec 26, 2024
69e10d9
feat: add landing page
mehdibha Jan 2, 2025
0f3b2ab
fix: format
mehdibha Jan 2, 2025
108d7a3
refactor: clean up project
mehdibha Jan 9, 2025
874550d
fix: format
mehdibha Jan 9, 2025
95cfa86
feat: landing page
mehdibha Jan 9, 2025
64a49c4
core: upgrade to next 15
mehdibha Jan 10, 2025
0f9b51b
refactor:rewrite alert component
mehdibha Jan 10, 2025
135a3f2
docs: update ComponentPreview
mehdibha Jan 11, 2025
eca6ffb
feat: style switcher
mehdibha Jan 11, 2025
3d318e9
fix: format
mehdibha Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions packages/tailwindcss-rac/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare function plugin(options?: Partial<{ prefix: string }>): {
handler: () => void
}

declare namespace plugin {
const __isOptionsFunction: true;
}

export = plugin
172 changes: 172 additions & 0 deletions packages/tailwindcss-rac/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
const plugin = require("tailwindcss/plugin");

// Order of these is important because it determines which states win in a conflict.
// We mostly follow Tailwind's defaults, adding our additional states following the categories they define.
// https://github.com/tailwindlabs/tailwindcss/blob/304c2bad6cb5fcb62754a4580b1c8f4c16b946ea/src/corePlugins.js#L83
const attributes = {
boolean: [
// Conditions
"allows-removing",
"allows-sorting",
"allows-dragging",
"has-submenu",

// States
"open",
"expanded",
"entering",
"exiting",
"indeterminate",
["placeholder-shown", "placeholder"],
"current",
"required",
"unavailable",
"invalid",
["read-only", "readonly"],
"outside-month",
"outside-visible-range",
"pending",

// Content
"empty",

// Interactive states
"focus-within",
["hover", "hovered"],
["focus", "focused"],
"focus-visible",
"pressed",
"selected",
"selection-start",
"selection-end",
"dragging",
"drop-target",
"resizing",
"disabled",
],
enum: {
placement: ["left", "right", "top", "bottom"],
type: ["literal", "year", "month", "day"],
layout: ["grid", "stack"],
orientation: ["horizontal", "vertical"],
"selection-mode": ["single", "multiple"],
"resizable-direction": ["right", "left", "both"],
"sort-direction": ["ascending", "descending"],
},
};

const shortNames = {
"selection-mode": "selection",
"resizable-direction": "resizable",
"sort-direction": "sort",
};

// Variants we use that are already defined by Tailwind:
// https://github.com/tailwindlabs/tailwindcss/blob/a2fa6932767ab328515f743d6188c2164ad2a5de/src/corePlugins.js#L84
const nativeVariants = [
"indeterminate",
"required",
"invalid",
"empty",
"focus-visible",
"focus-within",
"disabled",
];
const nativeVariantSelectors = new Map([
...nativeVariants.map((variant) => [variant, `:${variant}`]),
["hovered", ":hover"],
["focused", ":focus"],
["readonly", ":read-only"],
["open", "[open]"],
["expanded", "[expanded]"],
]);

// Variants where both native and RAC attributes should apply. We don't override these.
const nativeMergeSelectors = new Map([["placeholder", ":placeholder-shown"]]);

// If no prefix is specified, we want to avoid overriding native variants on non-RAC components, so we only target elements with the data-rac attribute for those variants.
let getSelector = (
prefix,
attributeName,
attributeValue,
hoverOnlyWhenSupported
) => {
let baseSelector = attributeValue
? `[data-${attributeName}="${attributeValue}"]`
: `[data-${attributeName}]`;
let nativeSelector = nativeVariantSelectors.get(attributeName);
if (prefix === "" && nativeSelector) {
let wrappedNativeSelector = `&:where(:not([data-rac]))${nativeSelector}`;
let nativeSelectorGenerator = wrappedNativeSelector;
if (nativeSelector === ":hover" && hoverOnlyWhenSupported) {
nativeSelectorGenerator = (wrap) =>
`@media (hover: hover) and (pointer: fine) { ${wrap(wrappedNativeSelector)} }`;
}
return [`&:where([data-rac])${baseSelector}`, nativeSelectorGenerator];
} else if (prefix === "" && nativeMergeSelectors.has(attributeName)) {
return [`&${baseSelector}`, `&${nativeMergeSelectors.get(attributeName)}`];
} else {
return `&${baseSelector}`;
}
};

let mapSelector = (selector, fn) => {
if (Array.isArray(selector)) {
return selector.map(fn);
} else {
return fn(selector);
}
};

let wrapSelector = (selector, wrap) => {
if (typeof selector === "function") {
return selector(wrap);
} else {
return wrap(selector);
}
};

let addVariants = (variantName, selectors, addVariant, matchVariant) => {
addVariant(
variantName,
mapSelector(selectors, (selector) => wrapSelector(selector, (s) => s))
);
};

module.exports = plugin.withOptions(
(options) =>
({ addVariant, matchVariant, config }) => {
let prefix = options?.prefix ? `${options.prefix}-` : "";
let future = config().future;
let hoverOnlyWhenSupported =
future === "all" || future?.hoverOnlyWhenSupported;

// Enum attributes go first because currently they are all non-interactive states.
Object.keys(attributes.enum).forEach((attributeName) => {
attributes.enum[attributeName].forEach((attributeValue) => {
let name = shortNames[attributeName] || attributeName;
let variantName = `${prefix}${name}-${attributeValue}`;
let selectors = getSelector(
prefix,
attributeName,
attributeValue,
hoverOnlyWhenSupported
);
addVariants(variantName, selectors, addVariant, matchVariant);
});
});

attributes.boolean.forEach((attribute) => {
let variantName = Array.isArray(attribute) ? attribute[0] : attribute;
variantName = `${prefix}${variantName}`;
let attributeName = Array.isArray(attribute) ? attribute[1] : attribute;
let selectors = getSelector(
prefix,
attributeName,
null,
hoverOnlyWhenSupported
);
addVariants(variantName, selectors, addVariant, matchVariant);
});
}
);
24 changes: 24 additions & 0 deletions packages/tailwindcss-rac/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "tailwindcss-rac",
"version": "1.2.0",
"description": "A Tailwind plugin that adds variants for data attributes in React Aria Components compatible with tailwind v4",
"license": "Apache-2.0",
"main": "index.js",
"types": "index.d.ts",
"source": "index.js",
"files": [
"dist",
"src"
],
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/mehdibha/dotUI"
},
"peerDependencies": {
"tailwindcss": "*"
},
"publishConfig": {
"access": "public"
}
}
Loading
Loading