-
Notifications
You must be signed in to change notification settings - Fork 204
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
feat: React Skeleton #2403
base: develop
Are you sure you want to change the base?
feat: React Skeleton #2403
Changes from 28 commits
a2701f5
e931d06
057a92f
0077f78
3d4d19c
9beb3b3
15994f8
c27f504
c295722
0b1ce02
25b4a1a
c56dacb
e59521e
e6bf1ec
8b2b753
a064fe7
322dc62
c9478eb
46bcda5
5f7ea35
16f8a1d
c8719b5
d045a63
44370c8
2585e5b
125f1b7
66f84ea
3e3ddd0
198afb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||
import { | ||||||
scopedPreflightStyles, | ||||||
isolateInsideOfContainer, | ||||||
} from 'tailwindcss-scoped-preflight'; | ||||||
|
||||||
const rootClass = '.dokan-layout'; //We will use this class to scope the styles. | ||||||
|
||||||
/** @type {import('tailwindcss').Config} */ | ||||||
const baseConfig = { | ||||||
important: rootClass, | ||||||
content: [ './src/**/*.{js,jsx,ts,tsx}', '!./**/*.asset.php' ], | ||||||
theme: { | ||||||
extend: { | ||||||
backgroundColor: { | ||||||
dokan: { | ||||||
sidebar: { | ||||||
DEFAULT: | ||||||
'var(--dokan-sidebar-background-color, #F05025)', | ||||||
hover: 'var(--dokan-sidebar-hover-background-color, #F05025)', | ||||||
}, | ||||||
btn: { | ||||||
DEFAULT: | ||||||
'var(--dokan-button-background-color, #F05025)', | ||||||
hover: 'var(--dokan-button-hover-background-color, #F05025)', | ||||||
secondary: { | ||||||
DEFAULT: | ||||||
'var(--dokan-button-secondary-background-color, var(--dokan-button-text-color))', | ||||||
hover: 'var(--dokan-button-secondary-hover-background-color, var(--dokan-button-background-color))', | ||||||
}, | ||||||
tertiary: { | ||||||
DEFAULT: | ||||||
'var(--dokan-button-tertiary-background-color, #00000000)', | ||||||
hover: 'var(--dokan-button-tertiary-hover-background-color, var(--dokan-button-text-color))', | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
textColor: { | ||||||
dokan: { | ||||||
sidebar: { | ||||||
DEFAULT: 'var(--dokan-sidebar-text-color, #CFCFCF)', | ||||||
hover: 'var(--dokan-sidebar-hover-text-color, #ffffff)', | ||||||
}, | ||||||
btn: { | ||||||
DEFAULT: 'var(--dokan-button-text-color, #ffffff)', | ||||||
hover: 'var(--dokan-button-hover-text-color, #ffffff)', | ||||||
secondary: { | ||||||
DEFAULT: | ||||||
'var(--dokan-button-secondary-text-color, var(--dokan-button-background-color))', | ||||||
hover: 'var(--dokan-button-secondary-hover-text-color, var(--dokan-button-text-color))', | ||||||
}, | ||||||
tertiary: { | ||||||
DEFAULT: | ||||||
'var(--dokan-button-tertiary-text-color, var(--dokan-button-background-color))', | ||||||
hover: 'var(--dokan-button-tertiary-hover-text-color, var(--dokan-button-background-color))', | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
borderColor: { | ||||||
dokan: { | ||||||
btn: { | ||||||
DEFAULT: 'var(--dokan-button-border-color, #F05025)', | ||||||
hover: 'var(--dokan-button-hover-border-color, #F05025)', | ||||||
secondary: { | ||||||
DEFAULT: | ||||||
'var(--dokan-button-secondary-border-color, var(--dokan-button-border-color))', | ||||||
hover: 'var(--dokan-button-secondary-hover-border-color, var(--dokan-button-border-color))', | ||||||
}, | ||||||
tertiary: { | ||||||
DEFAULT: | ||||||
'var(--dokan-button-tertiary-border-color, #00000000)', | ||||||
hover: 'var(--dokan-button-tertiary-hover-border-color, var(--dokan-button-border-color))', | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
colors: { | ||||||
primary: 'var(--dokan-button-background-color, #F05025)', | ||||||
dokan: { | ||||||
sidebar: 'var(--dokan-button-background-color, #1B233B)', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential typo in 'sidebar' color variable In line 51, the Apply this diff to correct the variable name: sidebar: 'var(--dokan-button-background-color, #1B233B)',
+ sidebar: 'var(--dokan-sidebar-background-color, #1B233B)', 📝 Committable suggestion
Suggested change
|
||||||
btn: 'var(--dokan-button-background-color, #F05025)', | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
plugins: [ | ||||||
scopedPreflightStyles( { | ||||||
isolationStrategy: isolateInsideOfContainer( rootClass, {} ), | ||||||
} ), | ||||||
require( '@tailwindcss/typography' ), | ||||||
require( '@tailwindcss/forms' ), | ||||||
], | ||||||
}; | ||||||
|
||||||
module.exports = baseConfig; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
# How to define a menu is available in `React` and its `PHP` override information. | ||
|
||
- [Introduction](#introduction) | ||
- [1. Declare a menu is available in `React`.](#1-declare-a-menu-is-available-in-react) | ||
- [Declare `React` menu in **Dokan Lite.**](#declare-react-menu-in-dokan-lite) | ||
- [Declare `React` menu in **Dokan Pro** or **External Plugin**.](#declare-react-menu-in-dokan-pro-or-external-plugin) | ||
- [2. Declare the Override templates for a React route.](#2-declare-the-override-templates-for-a-react-route) | ||
- [Define the override templates for a React route in Dokan Lite.](#define-the-override-templates-for-a-react-route-in-dokan-lite) | ||
- [Define the override templates for a React route in **Dokan Pro** or **External Plugin**.](#define-the-override-templates-for-a-react-route-in-dokan-pro-or-external-plugin) | ||
- [Define the override templates array structure.](#define-the-override-templates-array-structure) | ||
- [Manual Override from External Plugin](#manual-override-from-external-plugin) | ||
|
||
## Introduction | ||
This document will help you to define a menu is available in `React` and its `PHP` override information. | ||
|
||
|
||
## 1. Declare a menu is available in `React`. | ||
To declare a menu is available in `React`, you need to define `route` property during the menu registration. | ||
|
||
### Declare `React` menu in **Dokan Lite**. | ||
```php | ||
// includes/functions-dashboard-navigation.php#L27-L66 | ||
$menus = [ | ||
'dashboard' => [ | ||
'title' => __( 'Dashboard', 'dokan-lite' ), | ||
'icon' => '<i class="fas fa-tachometer-alt"></i>', | ||
'url' => dokan_get_navigation_url(), | ||
'pos' => 10, | ||
'permission' => 'dokan_view_overview_menu', | ||
'react_route' => '/', // <-- Define the route here | ||
], | ||
'products' => [ | ||
'title' => __( 'Products', 'dokan-lite' ), | ||
'icon' => '<i class="fas fa-briefcase"></i>', | ||
'url' => dokan_get_navigation_url( 'products' ), | ||
'pos' => 30, | ||
'permission' => 'dokan_view_product_menu', | ||
'react_route' => 'products', // <-- Define the route here | ||
], | ||
'orders' => [ | ||
'title' => __( 'Orders', 'dokan-lite' ), | ||
'icon' => '<i class="fas fa-shopping-cart"></i>', | ||
'url' => dokan_get_navigation_url( 'orders' ), | ||
'pos' => 50, | ||
'permission' => 'dokan_view_order_menu', | ||
'react_route' => 'orders', // <-- Define the route here | ||
], | ||
'withdraw' => [ | ||
'title' => __( 'Withdraw', 'dokan-lite' ), | ||
'icon' => '<i class="fas fa-upload"></i>', | ||
'url' => dokan_get_navigation_url( 'withdraw' ), | ||
'pos' => 70, | ||
'permission' => 'dokan_view_withdraw_menu', | ||
], | ||
'settings' => [ | ||
'title' => __( 'Settings', 'dokan-lite' ), | ||
'icon' => '<i class="fas fa-cog"></i>', | ||
'url' => dokan_get_navigation_url( 'settings/store' ), | ||
'pos' => 200, | ||
], | ||
]; | ||
``` | ||
In the above example, the `route` property is defined for each menu which we are indicating that the react route is available. | ||
This will be used to determine if the menu is pointing to the react Application or to the Legacy PHP Route. | ||
|
||
The `route` property should be the same as the route defined in the `React` application in Router Array. | ||
|
||
It is important to note that the `route` property should be defined for the menu which is available in the `React` application. | ||
If the `route` key is not defined for the menu, then the menu will be considered as a legacy menu and will be rendered using the PHP template. | ||
|
||
|
||
### Declare `React` menu in **Dokan Pro** or **External Plugin**. | ||
|
||
```php | ||
add_filter( 'dokan_get_dashboard_nav', function ( $menus ) { | ||
$menus['products'] = [ | ||
'title' => __( 'Products', 'dokan-lite' ), | ||
'icon' => '<i class="fas fa-briefcase"></i>', | ||
'url' => dokan_get_navigation_url( 'products' ), | ||
'pos' => 30, | ||
'permission' => 'dokan_view_product_menu', | ||
'react_route' => 'products', // <-- Define the route here | ||
]; | ||
|
||
return $menus; | ||
} ); | ||
``` | ||
|
||
|
||
## 2. Declare the Override templates for a React route. | ||
If you are writing a new feature or modifying an existing feature in the `React` application, you do not need to define the override templates for the `React` route. | ||
But if you are modifying or migrating an existing feature written in PHP to the `React` application and you want that if some of the PHP template is overridden by the existing PHP template then the legacy PHP page will be displayed, then you need to define the override templates for the `React` route. | ||
### Define the override templates for a React route in Dokan Lite. | ||
```php | ||
// VendorNavMenuChecker.php#L13-L26 | ||
protected array $template_dependencies = [ | ||
'' => [ | ||
[ 'slug' => 'dashboard/dashboard' ], | ||
[ 'slug' => 'dashboard/orders-widget' ], | ||
[ 'slug' => 'dashboard/products-widget' ], | ||
], | ||
'products' => [ | ||
[ 'slug' => 'products/products' ], | ||
[ | ||
'slug' => 'products/products', | ||
'name' => 'listing', | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
In the above example, the `template_dependencies` property is defined for each route which we are indicating that the override templates are available for the route. This will be used to determine if the override templates are available for the route or not. | ||
|
||
### Define the override templates for a React route in **Dokan Pro** or **External Plugin**. | ||
From Dokan Pro, we can add dependencies by using the filter `dokan_get_dashboard_nav_template_dependency`. | ||
|
||
```php | ||
add_filter( 'dokan_get_dashboard_nav_template_dependency', function ( array $dependencies ) { | ||
$dependencies['products'] = [ | ||
[ 'slug' => 'products/products' ], | ||
[ | ||
'slug' => 'products/products', | ||
'name' => 'listing', | ||
], | ||
]; | ||
|
||
return $dependencies; | ||
} ); | ||
``` | ||
### Define the override templates array structure. | ||
```php | ||
/** | ||
* @var array $template_dependencies Array of template dependencies for the route. | ||
*/ | ||
|
||
[ | ||
'route_name' => [ | ||
[ | ||
'slug' => 'template-slug', | ||
'name' => 'template-name' // (Optional), | ||
'args' = [] // (Optional) | ||
], | ||
] | ||
] | ||
``` | ||
|
||
- **Slug:** The slug of the template file which is used to display the php content. | ||
- **Name:** The name of the template file which is used to display the php content. (Optional) | ||
- **Args:** The arguments which are passed to the template file in `dokan_get_template_part()` function. (Optional) | ||
|
||
## Manual Override from External Plugin | ||
If you did not override any of the template file directly but you have override functionality by using `add_action` or `add_filter` then you can forcefully override the php route and template rendering for the route by using the `dokan_is_dashboard_nav_dependency_cleared` filter hook. | ||
|
||
```php | ||
|
||
add_filter( 'dokan_is_dashboard_nav_dependency_cleared', function ( $is_cleared, $route ) { | ||
if ( 'products' === $route ) { | ||
return true; | ||
} | ||
|
||
return $is_cleared; | ||
}, 10, 2 ); | ||
|
||
``` |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||||||||||||||||||
|
||||||||||||||||||||||
namespace WeDevs\Dokan; | ||||||||||||||||||||||
|
||||||||||||||||||||||
use Automattic\WooCommerce\Internal\Admin\WCAdminAssets; | ||||||||||||||||||||||
use WeDevs\Dokan\Admin\Notices\Helper; | ||||||||||||||||||||||
use WeDevs\Dokan\ReverseWithdrawal\SettingsHelper; | ||||||||||||||||||||||
use WeDevs\Dokan\ProductCategory\Helper as CategoryHelper; | ||||||||||||||||||||||
|
@@ -15,6 +16,11 @@ class Assets { | |||||||||||||||||||||
public function __construct() { | ||||||||||||||||||||||
add_action( 'init', [ $this, 'register_all_scripts' ], 10 ); | ||||||||||||||||||||||
add_filter( 'dokan_localized_args', [ $this, 'conditional_localized_args' ] ); | ||||||||||||||||||||||
add_action( | ||||||||||||||||||||||
'wp_footer', function () { | ||||||||||||||||||||||
echo '<div class="dokan-layout" id="headlessui-portal-root"><div></div></div>'; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
); | ||||||||||||||||||||||
|
||||||||||||||||||||||
if ( is_admin() ) { | ||||||||||||||||||||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ], 10 ); | ||||||||||||||||||||||
|
@@ -360,6 +366,10 @@ public function get_styles() { | |||||||||||||||||||||
'src' => DOKAN_PLUGIN_ASSEST . '/css/dokan-tailwind.css', | ||||||||||||||||||||||
'version' => filemtime( DOKAN_DIR . '/assets/css/dokan-tailwind.css' ), | ||||||||||||||||||||||
], | ||||||||||||||||||||||
'dokan-react-frontend' => [ | ||||||||||||||||||||||
'src' => DOKAN_PLUGIN_ASSEST . '/css/frontend.css', | ||||||||||||||||||||||
'version' => filemtime( DOKAN_DIR . '/assets/css/frontend.css' ), | ||||||||||||||||||||||
], | ||||||||||||||||||||||
]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
return $styles; | ||||||||||||||||||||||
|
@@ -373,6 +383,7 @@ public function get_styles() { | |||||||||||||||||||||
public function get_scripts() { | ||||||||||||||||||||||
global $wp_version; | ||||||||||||||||||||||
|
||||||||||||||||||||||
$frontend_shipping_asset = require DOKAN_DIR . '/assets/js/frontend.asset.php'; | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the variable name to match the asset being loaded The variable Apply this diff to correct the variable name: -$frontend_shipping_asset = require DOKAN_DIR . '/assets/js/frontend.asset.php';
+$frontend_asset = require DOKAN_DIR . '/assets/js/frontend.asset.php'; Ensure to update all references to 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | ||||||||||||||||||||||
$asset_url = DOKAN_PLUGIN_ASSEST; | ||||||||||||||||||||||
$asset_path = DOKAN_DIR . '/assets/'; | ||||||||||||||||||||||
|
@@ -567,6 +578,11 @@ public function get_scripts() { | |||||||||||||||||||||
'deps' => [ 'jquery' ], | ||||||||||||||||||||||
'version' => filemtime( $asset_path . 'js/dokan-frontend.js' ), | ||||||||||||||||||||||
], | ||||||||||||||||||||||
'dokan-react-frontend' => [ | ||||||||||||||||||||||
'src' => $asset_url . '/js/frontend.js', | ||||||||||||||||||||||
'deps' => $frontend_shipping_asset['dependencies'], | ||||||||||||||||||||||
'version' => $frontend_shipping_asset['version'], | ||||||||||||||||||||||
], | ||||||||||||||||||||||
Comment on lines
+581
to
+585
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update variable references after renaming Following the renaming of Apply this diff to update the variable references: 'dokan-react-frontend' => [
'src' => $asset_url . '/js/frontend.js',
- 'deps' => $frontend_shipping_asset['dependencies'],
- 'version' => $frontend_shipping_asset['version'],
+ 'deps' => $frontend_asset['dependencies'],
+ 'version' => $frontend_asset['version'],
], 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
return $scripts; | ||||||||||||||||||||||
|
@@ -873,6 +889,11 @@ public function dokan_dashboard_scripts() { | |||||||||||||||||||||
self::load_form_validate_script(); | ||||||||||||||||||||||
$this->load_gmap_script(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
$wc_instance = WCAdminAssets::get_instance(); | ||||||||||||||||||||||
$wc_instance->register_scripts(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
wp_enqueue_script( 'dokan-react-frontend' ); | ||||||||||||||||||||||
wp_enqueue_style( 'dokan-react-frontend' ); | ||||||||||||||||||||||
Comment on lines
+895
to
+896
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Conditionally enqueue 'dokan-react-frontend' assets to optimize performance Currently, the scripts and styles for For example, you can modify the code to enqueue the assets conditionally: if ( /* condition to check if the assets are needed */ ) {
wp_enqueue_script( 'dokan-react-frontend' );
wp_enqueue_style( 'dokan-react-frontend' );
} Replace |
||||||||||||||||||||||
wp_enqueue_script( 'jquery' ); | ||||||||||||||||||||||
wp_enqueue_script( 'jquery-ui' ); | ||||||||||||||||||||||
wp_enqueue_script( 'jquery-ui-autocomplete' ); | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 'exclude' option instead of negation in 'content' array
In line 11, the
content
array includes a negation pattern'!./**/*.asset.php'
. Tailwind CSS does not support negation patterns in thecontent
array. Instead, you should use theexclude
option to exclude files or directories.Apply this diff to correct the configuration: