generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add uikit plugin instead of theme render props
- Loading branch information
Showing
8 changed files
with
109 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import {createGoogleAnalyticsPlugin} from './google-analytics/index.js'; | ||
import {createLayoutPlugin} from './layout/index.js'; | ||
import type {LayoutInitOptions} from './layout/index.js'; | ||
import {createUikitPlugin} from './uikit/index.js'; | ||
import {createYandexMetrikaPlugin} from './yandex-metrika/index.js'; | ||
|
||
export function createDefaultPlugins({layout}: {layout: LayoutInitOptions}) { | ||
return [createGoogleAnalyticsPlugin(), createYandexMetrikaPlugin(), createLayoutPlugin(layout)]; | ||
return [ | ||
createGoogleAnalyticsPlugin(), | ||
createYandexMetrikaPlugin(), | ||
createUikitPlugin(), | ||
createLayoutPlugin(layout), | ||
]; | ||
} | ||
|
||
export {createGoogleAnalyticsPlugin, createYandexMetrikaPlugin, createLayoutPlugin}; | ||
export { | ||
createGoogleAnalyticsPlugin, | ||
createYandexMetrikaPlugin, | ||
createLayoutPlugin, | ||
createUikitPlugin, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type {Plugin} from '../../types.js'; | ||
|
||
import type {UikitPluginOptions} from './types.js'; | ||
|
||
export type {UikitPluginOptions} from './types.js'; | ||
|
||
export function createUikitPlugin(): Plugin<UikitPluginOptions, 'uikit'> { | ||
return { | ||
name: 'uikit', | ||
apply({options, renderContent}) { | ||
if (!options) { | ||
return; | ||
} | ||
|
||
const {theme, direction} = options; | ||
|
||
const cls = renderContent.bodyContent.attributes.class; | ||
const className = Array.from( | ||
new Set([...(cls ? String(cls).split(/\s+/) : []), ...getRootClassName(theme)]), | ||
) | ||
.filter(Boolean) | ||
.join(' '); | ||
renderContent.bodyContent.attributes.class = className; | ||
|
||
if (direction === 'rtl') { | ||
renderContent.bodyContent.attributes.dir = 'rtl'; | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
function getRootClassName(theme: string) { | ||
const classes = ['g-root']; | ||
classes.push(`g-root_theme_${theme}`); | ||
return classes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface UikitPluginOptions { | ||
theme: string; | ||
direction?: 'ltr' | 'rtl'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters