Dokan frontend dev

From getdokan/dokan · View interactive version

Dokan frontend dev is an AI agent skill from the GitHub repository getdokan/dokan. Add or modify Dokan frontend code (React, TypeScript, Vue, Tailwind). Use when creating components, hooks, stores, or modifying webpack configuration.

How to use this skill

Skill file

Dokan Frontend Development

This skill provides guidance for developing Dokan Lite frontend code.

Settings: when the change adds, changes, or reads a setting (routes, nav, cards, Store renderers), also load dokan-setting-impact and run its Build gate.

Tech Stack

| Technology | Usage | Files |

|---|---|---|

| React + TypeScript | New admin/dashboard components | .tsx files in src/ |

| Vue 2.7 | Legacy vendor dashboard & frontend | .vue files, main.js entry points |

| Tailwind CSS | Styling (with WordPress compat) | tailwind.config.js |

| Less | Legacy styles | assets/src/less/ |

| @wordpress/data | State management (Redux-like) | src/stores/ |

| Webpack 5 | Build system (80+ entry points) | webpack.config.js, webpack-entries.js |

React Components

Conventions

import { Button as DokanUIButton } from '@getdokan/dokan-ui';
import { twMerge } from 'tailwind-merge';

const DokanButton = ({ className = '', variant = 'primary', ...props }: DokanButtonProps) => {
    const config = variantConfig[variant];
    return (
        <DokanUIButton
            color={config.color}
            className={twMerge(config.className, className)}
            {...props}
        />
    );
};

export default DokanButton;

Barrel Exports

Export from index.tsx in component directories:

// src/components/index.tsx
export { default as DokanButton } from './Button';
export { default as DokanModal } from './modals/DokanModal';
export { default as DataViews } from './dataviews/DataViewTable';

Global Libraries

Components are exposed globally on window.dokan:

Custom Hooks

Located in src/hooks/, TypeScript, use prefix:

import { useSelect } from '@wordpress/data';

export const useCurrentUser = () => {
    return useSelect((select) => {
        return select('dokan/core').getCurrentUser();
    }, []);
};

Available: useCategories, useCurrentUser, useCustomerById, useCustomerSearch, useMutationObserver, usePermission, useProducts, ViewportDimensions.

State Management

Uses @wordpress/data (Redux-like) stores in src/stores/:

src/stores/
├── core/              # dokan/core store
│   ├── actions.ts
│   ├── reducer.ts
│   ├── selectors.ts
│   ├── resolvers.ts
│   └── defaultState.ts
├── productCategories/
├── products/
└── vendors/

Store creation:

import { createReduxStore } from '@wordpress/data';

export const DOKAN_CORE_STORE = 'dokan/core';

const store = createReduxStore<CoreState, typeof actions, typeof selectors>(
    DOKAN_CORE_STORE,
    { reducer, selectors, actions, resolvers }
);

Tailwind CSS

Config: tailwind.config.js (extends base-tailwind.config.js)

TypeScript

Config: tsconfig.json

Webpack

Config: webpack.config.js (extends @wordpress/scripts default config)

Adding a New Entry Point

Add to webpack-entries.js:

module.exports = {
    // ...existing entries
    'my-feature': './src/my-feature/index.tsx',
};

Localization / Translation (JavaScript)

Library: @wordpress/i18n — WordPress's official i18n package.

React / TypeScript

import { __, _n, sprintf } from '@wordpress/i18n';

// Simple translation
const label = __( 'Save changes', 'dokan-lite' );

// With sprintf for dynamic content
const message = sprintf(
    /* translators: %s: vendor name */
    __( 'Welcome, %s!', 'dokan-lite' ),
    vendorName
);

// Pluralization
const itemLabel = sprintf(
    _n( '%d item', '%d items', count, 'dokan-lite' ),
    count
);

// In JSX
<button>{ __( 'Submit', 'dokan-lite' ) }</button>

Translator Comments

Always add /* translators: */ comments before sprintf() with placeholders — these are extracted into the POT file:

sprintf(
    /* translators: 1: start date 2: end date */
    __( 'From %1$s to %2$s', 'dokan-lite' ),
    startDate,
    endDate
)

Vue 2.7 (Legacy)

Vue components use a translation mixin from src/utils/Mixin.js that wraps @wordpress/i18n:

<template>
    <h2>{{ __( 'Dashboard', 'dokan-lite' ) }}</h2>
</template>

<script>
import Mixin from 'admin/utils/Mixin';

export default {
    mixins: [ Mixin ],
};
</script>

Available mixin methods: __(), _x(), __n(), _nx(), sprintf().

Script Translation Registration (PHP side)

When registering a new script, translations are auto-registered via wp_set_script_translations() in includes/Assets.php. For custom scripts:

wp_set_script_translations( 'my-script-handle', 'dokan-lite', plugin_dir_path( DOKAN_FILE ) . 'languages' );

Localized Data (PHP → JS)

Server-side data is passed to JS via wp_localize_script(). Access via window.dokan:

Filter hooks for extending: dokan_helper_localize_script, dokan_frontend_localize_script, dokan_admin_localize_script.

Key Rules

Vue 2.7 (Legacy)

Older components use Vue 2.7 with .vue files. New development should use React unless modifying existing Vue code. Vue entry points typically use main.js.

Key Reference Files

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.