Skip to content

Commit

Permalink
Merge pull request #403 from pankod/RK-682-superplate-add-tailwind-pr…
Browse files Browse the repository at this point in the history
…eset

Rk 682 superplate add tailwind preset
  • Loading branch information
alicanerdurmaz authored Jun 5, 2024
2 parents 523b9d4 + bae2e93 commit bcdf56d
Show file tree
Hide file tree
Showing 66 changed files with 573 additions and 115 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const buildRemote = async () => {
antd: "antd-example",
mui: "mui-example",
no: "headless-example",
tailwindcss: "headless-example",
};

let AUTH_PROVIDER = dataProviderMap[DATA_PROVIDER];
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const buildTemplate = async () => {
antd: "antd-example",
mui: "mui-example",
no: "headless-example",
tailwindcss: "headless-example",
};

let AUTH_PROVIDER = dataProviderMap[DATA_PROVIDER];
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
appwrite,
hasura,
]
ui_framework: [antd, mui, no]
ui_framework: [tailwindcss, antd, mui, no]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
appwrite,
hasura,
]
ui_framework: [antd, mui, no]
ui_framework: [tailwindcss, antd, mui, no]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
appwrite,
hasura,
]
ui_framework: [antd, mui, no]
ui_framework: [tailwindcss, antd, mui, no]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-remote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
appwrite,
hasura,
]
ui_framework: [antd, mui, no]
ui_framework: [tailwindcss, antd, mui, no]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
appwrite,
hasura,
]
ui_framework: [antd, mui, no]
ui_framework: [tailwindcss, antd, mui, no]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
appwrite,
hasura,
]
ui_framework: [antd, mui, no]
ui_framework: [tailwindcss, antd, mui, no]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
10 changes: 8 additions & 2 deletions cypress/e2e/build-test.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ describe("build test", () => {

cy.contains("Sign in to your account").should("exist");

if (Cypress.env("UI_FRAMEWORK") === "no") {
if (
Cypress.env("UI_FRAMEWORK") === "no" ||
Cypress.env("UI_FRAMEWORK") === "tailwindcss"
) {
if (Cypress.env("DATA_PROVIDER") === "supabase") {
cy.get("input[name='email']").type("[email protected]");
cy.get("input[name='password']").type("refine-supabase");
Expand Down Expand Up @@ -125,7 +128,10 @@ describe("build test", () => {
cy.title().should("eq", "Blog posts | Refine");
}

if (Cypress.env("UI_FRAMEWORK") !== "no") {
if (
Cypress.env("UI_FRAMEWORK") !== "no" &&
Cypress.env("UI_FRAMEWORK") !== "tailwindcss"
) {
cy.contains("Categories").should("exist");

cy.contains("Logout").should("exist");
Expand Down
37 changes: 37 additions & 0 deletions presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,42 @@ 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",
},
},
{
name: "refine-remix-tailwind",
type: "refine-remix",
answers: {
"ui-framework": "tailwindcss",
"data-provider": "data-provider-custom-json-rest",
"auth-provider": "none",
"antd-example": "no",
"mui-example": "no",
"headless-example": "no",
},
},
],
};
35 changes: 15 additions & 20 deletions refine-nextjs/plugins/_base/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module.exports = {
const uiFramework = answers["ui-framework"];
const dataProvider = answers["data-provider"];
const authProvider = answers["auth-provider"];
const isHeadless =
uiFramework === "no" || uiFramework === "tailwindcss";

// ## isNextAuthCheck
if (
Expand Down Expand Up @@ -67,7 +69,7 @@ module.exports = {
];

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

if (
answers["ui-framework"] !== "no" &&
(answers["title"] || answers["svg"])
) {
if (!isHeadless && (answers["title"] || answers["svg"])) {
if (answers["ui-framework"] === "antd") {
base._app.refineAntdImports.push("ThemedTitleV2");
}
Expand All @@ -129,24 +128,21 @@ module.exports = {
}
}

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";`,
);
base._app.localImport.push(`import "@styles/global.css";`);
}

// this impementation required for getting default ColorModeContextProvider's theme from cookie
if (answers["ui-framework"] !== "no") {
if (!isHeadless) {
base._app.nextjsInner.push(
`const cookieStore = cookies();`,
`const theme = cookieStore.get("theme");`,
Expand Down Expand Up @@ -187,7 +183,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 @@ -196,7 +192,7 @@ module.exports = {

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

Expand All @@ -239,17 +235,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 @@ -9,7 +9,7 @@
AuthPage as AuthPageBase,
} from "@refinedev/mui";
<%_ } _%>
<%_ if (answers[`ui-framework`] === "no") { _%>
<%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%>
import { AuthPage as AuthPageBase } from "@refinedev/core";
<%_ } _%>
import type { AuthPageProps } from '@refinedev/core'
Expand Down
1 change: 1 addition & 0 deletions refine-nextjs/plugins/_base/src/styles/global.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
body {
margin: 0px;
background: white;
}

table {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import routerProvider from "@refinedev/nextjs-router";
%>

type RefineContextProps = {
<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
defaultMode?: string;
<%_ } _%>
};
Expand All @@ -42,7 +42,7 @@ export const RefineContext = (props: React.PropsWithChildren<RefineContextProps>
}

type AppProps = {
<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
defaultMode?: string;
<%_ } _%>
};
Expand Down Expand Up @@ -120,7 +120,7 @@ const App = (props: React.PropsWithChildren<AppProps>) => {
};


<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
const defaultMode = props?.defaultMode
<%_ } _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function Login() {
);
<%_ } _%>

<%_ 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 @@ -28,7 +28,7 @@ import routerProvider from "@refinedev/nextjs-router";
%>

type RefineContextProps = {
<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
defaultMode?: string;
<%_ } _%>
};
Expand All @@ -42,7 +42,7 @@ export const RefineContext = (props: React.PropsWithChildren<RefineContextProps>
}

type AppProps = {
<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
defaultMode?: string;
<%_ } _%>
};
Expand Down Expand Up @@ -120,7 +120,7 @@ const App = (props: React.PropsWithChildren<AppProps>) => {
};


<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
const defaultMode = props?.defaultMode
<%_ } _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function Login() {
);
<%_ } _%>

<%_ 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 @@ -28,7 +28,7 @@ import routerProvider from "@refinedev/nextjs-router";
%>

type RefineContextProps = {
<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
defaultMode?: string;
<%_ } _%>
};
Expand All @@ -42,7 +42,7 @@ export const RefineContext = (props: React.PropsWithChildren<RefineContextProps>
}

type AppProps = {
<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
defaultMode?: string;
<%_ } _%>
};
Expand Down Expand Up @@ -120,7 +120,7 @@ const App = (props: React.PropsWithChildren<AppProps>) => {
};


<%_ if (answers["ui-framework"] !== 'no') { _%>
<%_ if (answers["ui-framework"] !== "no" && answers["ui-framework"] !== "tailwindcss") { _%>
const defaultMode = props?.defaultMode
<%_ } _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function Login() {
);
<%_ } _%>

<%_ 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-nextjs/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-nextjs/plugins/tailwindcss/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"devDependencies": {
"tailwindcss": "^3.4.3",
"postcss": "^8.4.38",
"autoprefixer": "^10.4.19"
}
}
6 changes: 6 additions & 0 deletions refine-nextjs/plugins/tailwindcss/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
Loading

0 comments on commit bcdf56d

Please sign in to comment.