Skip to content

Commit

Permalink
feat: add tailwind vite
Browse files Browse the repository at this point in the history
  • Loading branch information
alicanerdurmaz committed May 31, 2024
1 parent 208f02f commit 23ddc56
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 25 deletions.
25 changes: 25 additions & 0 deletions presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,30 @@ module.exports = {
"headless-example": "no",
},
},
{
name: "refine-vite-tailwind",
type: "refine-vite",
answers: {
"ui-framework": "tailwindcss",
"router-provider": "react-router-v6",
"data-provider": "data-provider-custom-json-rest",
"auth-provider": "none",
"antd-example": "no",
"mui-example": "no",
"headless-example": "no",
},
},
{
name: "refine-nextjs-tailwind",
type: "refine-nextjs",
answers: {
"ui-framework": "tailwindcss",
"data-provider": "data-provider-custom-json-rest",
"auth-provider": "none",
"antd-example": "no",
"mui-example": "no",
"headless-example": "no",
},
},
],
};
28 changes: 13 additions & 15 deletions refine-vite/plugins/_base/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module.exports = {
extend(answers) {
const uiFramework = answers["ui-framework"];
const dataProvider = answers["data-provider"];
const isHeadless =
uiFramework === "no" || uiFramework === "tailwindcss";

switch (uiFramework) {
case "antd":
Expand Down Expand Up @@ -102,7 +104,7 @@ module.exports = {
];

// update for headless
if (uiFramework === "no") {
if (isHeadless) {
base._app.authPageProps = [
`
renderContent={(content) => (
Expand Down Expand Up @@ -160,16 +162,13 @@ module.exports = {
base.selectedSvg = svgFromAnswers;
}

if (
answers["ui-framework"] !== "no" &&
(answers["title"] || answers["svg"])
) {
if (!isHeadless && (answers["title"] || answers["svg"])) {
base._app.localImport.push(
'import { AppIcon } from "./components/app-icon";',
);
}

if (answers["ui-framework"] === "no") {
if (isHeadless) {
base._app.localImport.push(
`import { Layout } from "./components/layout";`,
);
Expand Down Expand Up @@ -200,7 +199,7 @@ module.exports = {
} else if (dataProvider === "data-provider-supabase") {
base.blogPostCategoryIdFormField = `"categoryId"`;
} else {
if (uiFramework === "mui" || uiFramework === "no") {
if (uiFramework === "mui" || isHeadless) {
base.blogPostCategoryIdFormField = `"category.id"`;
} else {
base.blogPostCategoryIdFormField = `["category", "id"]`;
Expand All @@ -209,7 +208,7 @@ module.exports = {

// ## blogPostCategoryTableField
if (base.isGraphQL) {
if (uiFramework === "no") {
if (isHeadless) {
base.blogPostCategoryTableField = `"category.title"`;
}
if (uiFramework === "antd") {
Expand Down Expand Up @@ -240,7 +239,7 @@ module.exports = {
{ value: "rejected", label: "Rejected" },
]);
}
if (uiFramework === "no" || uiFramework === "mui") {
if (isHeadless || uiFramework === "mui") {
base.blogPostStatusOptions = JSON.parse(base.blogPostStatusOptions);
}

Expand All @@ -252,17 +251,16 @@ module.exports = {
}

// ## Refine options.title
if (
answers["ui-framework"] !== "no" &&
(answers["title"] || answers["svg"])
) {
if (!isHeadless && (answers["title"] || answers["svg"])) {
if (!base._app.refineOptions) {
base._app.refineOptions = [];
}
const textLine = answers["title"] ? `text: "${answers["title"]}",` : "";
const textLine = answers["title"]
? `text: "${answers["title"]}",`
: "";
const iconLine = answers["svg"] ? `icon: <AppIcon />,` : "";
const template = `title: { ${textLine} ${iconLine} },`;

base._app.refineOptions.push(template);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const Login: React.FC = () => {
);
<%_ } _%>

<%_ if (answers["ui-framework"] === "no") { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
return(
<div
style={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%_ if (answers[`ui-framework`] === "no") { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
import { AuthPage } from "@refinedev/core";
<%_ } _%>
<%_ if (answers["ui-framework"] === 'antd') { _%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%_ if (answers[`ui-framework`] === "no") { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
import { AuthPage } from "@refinedev/core";
<%_ } _%>
<%_ if (answers["ui-framework"] === 'antd') { _%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%_ if (answers[`ui-framework`] === "no") { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
import { AuthPage } from "@refinedev/core";
<%_ } _%>
<%_ if (answers["ui-framework"] === 'antd') { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const Login: React.FC = () => {
);
<%_ } _%>

<%_ if (answers["ui-framework"] === "no") { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
return(
<div
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const Login: React.FC = () => {
);
<%_ } _%>

<%_ if (answers["ui-framework"] === "no") { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
return(
<div
style={{
Expand Down
4 changes: 4 additions & 0 deletions refine-vite/plugins/tailwindcss/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Tailwind CSS",
"url": "https://refine.dev/docs/guides-concepts/general-concepts/#headless-concept"
}
7 changes: 7 additions & 0 deletions refine-vite/plugins/tailwindcss/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"tailwindcss": "^3.4.3",
"postcss": "^8.4.38",
"autoprefixer": "^10.4.19"
}
}
6 changes: 6 additions & 0 deletions refine-vite/plugins/tailwindcss/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
92 changes: 92 additions & 0 deletions refine-vite/plugins/tailwindcss/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

body {
margin: 0px;
}

table {
border-spacing: 0;
border: 1px solid black;
}

table th,
td {
margin: 0;
padding: 0.5rem;
border-bottom: 1px solid black;
border-right: 1px solid black;
}

table tr:last-child td {
border-bottom: 0;
}

table th,
td {
margin: 0;
padding: 0.5rem;
border-bottom: 1px solid black;
border-right: 1px solid black;
}

table th:last-child,
td:last-child {
border-right: 0;
}

.layout {
display: flex;
gap: 16px;
}

@media screen and (max-width: 751px) {
.layout {
display: block;
}
}

.layout .content {
display: flex;
flex-direction: column;
flex-grow: 1;
}

.breadcrumb {
display: flex;
gap: 24px;
list-style-type: "/ ";
padding: 8px 16px;
border-bottom: 1px solid lightgray;
}

.breadcrumb a {
color: blue;
text-decoration: none;
}

.menu {
flex-shrink: 0;
padding: 8px 16px;
border-right: 1px solid lightgray;
}

.menu a {
color: black;
}

.menu .active {
font-weight: bold;
}

@media screen and (max-width: 751px) {
.menu {
border-right: none;
border-bottom: 1px solid lightgray;
}
}

.menu ul {
padding-left: 16px;
}
8 changes: 8 additions & 0 deletions refine-vite/plugins/tailwindcss/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {},
},
plugins: [],
};
13 changes: 11 additions & 2 deletions refine-vite/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ module.exports = {
name: "mui",
hint: "Installs Material UI package.",
},
{
message: "Tailwind CSS",
name: "tailwindcss",
hint: "Installs Tailwind CSS package.",
},
],
default: "no",
},
Expand Down Expand Up @@ -207,15 +212,19 @@ module.exports = {
when: function (answers) {
return (
typeof answers["svg"] === "undefined" ||
answers["ui-framework"] === "no"
answers["ui-framework"] === "no" ||
answers["ui-framework"] === "tailwindcss"
);
},
pattern: ["src/components/app-icon/index.tsx"],
},
{
plugin: ["_base"],
when: function (answers) {
return answers["ui-framework"] !== "no";
return (
answers["ui-framework"] !== "no" &&
answers["ui-framework"] !== "tailwindcss"
);
},
pattern: [
"src/components/breadcrumb/index.tsx",
Expand Down
4 changes: 2 additions & 2 deletions refine-vite/template/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function App() {
key="authenticated-inner"
fallback={<CatchAllNavigate to="/login" />}
>
<%_ if (answers["ui-framework"] === 'no') { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
<Layout>
<Outlet />
</Layout>
Expand Down Expand Up @@ -174,7 +174,7 @@ function App() {
<Routes>
<Route
element={(
<%_ if (answers["ui-framework"] === 'no') { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
<Layout>
<Outlet />
</Layout>
Expand Down

0 comments on commit 23ddc56

Please sign in to comment.