diff --git a/src/common.ts b/src/common.ts index 7ad78c4..9090cfb 100644 --- a/src/common.ts +++ b/src/common.ts @@ -35,6 +35,8 @@ export enum TabsVariants { Accordion = 'accordion', } +export type EnabledVariants = Partial>; + export interface Tab { group?: string; key: string; diff --git a/src/plugin/find.ts b/src/plugin/find.ts index 2e189ac..90f870c 100644 --- a/src/plugin/find.ts +++ b/src/plugin/find.ts @@ -46,7 +46,7 @@ export function props(content: string): TabsProps { const props = clean.split(' '); const result: TabsProps = { content: clean, - orientation: TabsVariants.Regular, + variant: TabsVariants.Regular, group: `${DEFAULT_TABS_GROUP_PREFIX}${generateID()}`, }; @@ -58,7 +58,7 @@ export function props(content: string): TabsProps { case 'radio': case 'dropdown': case 'accordion': - result.orientation = key as TabsVariants; + result.variant = key as TabsVariants; break; case 'group': result.group = unquote(value); diff --git a/src/plugin/generate.ts b/src/plugin/generate.ts index 194fdc3..4b94508 100644 --- a/src/plugin/generate.ts +++ b/src/plugin/generate.ts @@ -9,7 +9,7 @@ export function generateTabsTokens( state: StateCore, props: TabsGenerationProps, ) { - const tokens = generateTokensByType(props.orientation)(tabs, state, props); + const tokens = generateTokensByType(props.variant)(tabs, state, props); return tokens; } diff --git a/src/plugin/transform.ts b/src/plugin/transform.ts index 73f41a5..31c9ac1 100644 --- a/src/plugin/transform.ts +++ b/src/plugin/transform.ts @@ -1,6 +1,8 @@ import type StateCore from 'markdown-it/lib/rules_core/state_core'; import type MarkdownIt from 'markdown-it'; +import {EnabledVariants, TabsVariants} from '../common'; + import {addHiddenProperty, copyRuntimeFiles} from './utils'; import {generateTabsTokens} from './generate'; import {findTabs, props, tryToFindTabs} from './find'; @@ -10,8 +12,17 @@ export type PluginOptions = { runtimeCssPath: string; containerClasses: string; bundle: boolean; + features: { + enabledVariants: EnabledVariants; + }; }; +const defaultFeatures = { + enabledVariants: { + regular: true, + }, +} satisfies PluginOptions['features']; + let runsCounter = 0; type TransformOptions = { @@ -23,6 +34,7 @@ export function transform({ runtimeCssPath = '_assets/tabs-extension.css', containerClasses = '', bundle = true, + features = defaultFeatures, }: Partial = {}) { return function tabs(md: MarkdownIt, options?: TransformOptions) { const {output = '.'} = options || {}; @@ -46,15 +58,19 @@ export function transform({ const {content, closeTokenIndex} = result; - const {group, orientation} = props(content); + const parsedProps = props(content); + + if (!features.enabledVariants[parsedProps.variant]) { + parsedProps.variant = TabsVariants.Regular; + } const tabs = findTabs(state.tokens, i + 3, closeTokenIndex); if (tabs.length > 0) { const tabsTokens = generateTabsTokens(tabs, state, { containerClasses, - tabsGroup: group, - orientation, + tabsGroup: parsedProps.group, + variant: parsedProps.variant, runId, }); diff --git a/src/plugin/types.ts b/src/plugin/types.ts index 1e7a139..3930c33 100644 --- a/src/plugin/types.ts +++ b/src/plugin/types.ts @@ -9,6 +9,6 @@ export type RuntimeTab = { export type TabsProps = { content: string; - orientation: TabsVariants; + variant: TabsVariants; group: string; }; diff --git a/src/plugin/variants/regular.ts b/src/plugin/variants/regular.ts index 4a1c71e..d3dc16d 100644 --- a/src/plugin/variants/regular.ts +++ b/src/plugin/variants/regular.ts @@ -20,7 +20,7 @@ import {TabsTokensGenerator} from './types'; export const regular: TabsTokensGenerator = ( tabs, state, - {containerClasses, tabsGroup, runId, orientation}, + {containerClasses, tabsGroup, runId, variant: orientation}, ) => { const tabsTokens = []; const tabListTokens = []; diff --git a/src/plugin/variants/types.ts b/src/plugin/variants/types.ts index 1748874..312c303 100644 --- a/src/plugin/variants/types.ts +++ b/src/plugin/variants/types.ts @@ -13,7 +13,7 @@ export type TabsGenerationProps = { containerClasses: string; tabsGroup: string; runId: string; - orientation: TabsVariants; + variant: TabsVariants; }; export type TabsTokensGenerator = ( diff --git a/tests/src/plugin.test.ts b/tests/src/plugin.test.ts index 55eef0c..b225c9b 100644 --- a/tests/src/plugin.test.ts +++ b/tests/src/plugin.test.ts @@ -64,7 +64,11 @@ function makeTransform(params?: { content?: string[]; }) { return callPlugin( - tabsExtension.transform({bundle: false, ...params?.transformOptions}), + tabsExtension.transform({ + bundle: false, + features: {enabledVariants: {radio: true, regular: true}}, + ...params?.transformOptions, + }), tokenize(params?.content || defaultContent), ); } @@ -72,7 +76,13 @@ function makeTransform(params?: { function html(text: string, opts?: tabsExtension.PluginOptions) { const {result} = transform(text, { needToSanitizeHtml: false, - plugins: [tabsExtension.transform({bundle: false, ...opts})], + plugins: [ + tabsExtension.transform({ + bundle: false, + features: {enabledVariants: {radio: true, regular: true}}, + ...opts, + }), + ], }); return result.html;