Skip to content

Commit ef85b0c

Browse files
committed
docs(headless/tabs): refactored all examples
1 parent c6385e1 commit ef85b0c

18 files changed

+334
-723
lines changed

apps/website/.eslintrc.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"extends": [
3+
"../../.eslintrc.json",
34
"eslint:recommended",
45
"plugin:@typescript-eslint/recommended",
5-
"plugin:qwik/recommended",
6-
"../../.eslintrc.json"
6+
"plugin:qwik/recommended"
77
],
88
"parser": "@typescript-eslint/parser",
99
"parserOptions": {
@@ -12,9 +12,7 @@
1212
"sourceType": "module",
1313
"ecmaFeatures": {
1414
"jsx": true
15-
},
16-
"parser": "@typescript-eslint/parser",
17-
"tsconfigRootDir": "__dirname"
15+
}
1816
},
1917
"plugins": ["@typescript-eslint"],
2018
"ignorePatterns": ["!**/*"],

apps/website/src/_state/app-state.type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { NoSerialize } from '@builder.io/qwik';
12
import type { Highlighter } from 'shiki';
23

34
export interface AppState {
45
mode: 'light' | 'dark';
5-
highlighter?: Highlighter;
6+
highlighter?: NoSerialize<Highlighter>;
67
isSidebarOpened: boolean;
78
featureFlags?: {
89
showFluffy?: boolean;

apps/website/src/_state/use-app-state.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
import { useContext, useContextProvider, useStore } from '@builder.io/qwik';
1+
import { useContext } from '@builder.io/qwik';
22
import { APP_STATE_CONTEXT_ID } from './app-state-context-id';
3-
import { AppState } from './app-state.type';
4-
5-
export const useAppStateProvider = () => {
6-
const appState = useStore<AppState>({
7-
mode: 'light',
8-
isSidebarOpened: false,
9-
featureFlags: {
10-
showFluffy: import.meta.env.DEV,
11-
},
12-
});
13-
14-
// useTask$(async function createHighlighter() {
15-
// const highlighter = await shiki.getHighlighter({ theme: 'css-variables' });
16-
// appState.highlighter = highlighter;
17-
// });
18-
19-
useContextProvider(APP_STATE_CONTEXT_ID, appState);
20-
21-
return appState;
22-
};
233

244
export const useAppState = () => {
255
const appState = useContext(APP_STATE_CONTEXT_ID);

apps/website/src/root.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
} from '@builder.io/qwik-city';
1313
import { RouterHead } from './routes/_components/router-head/router-head';
1414

15-
import { useAppStateProvider } from './_state/use-app-state';
15+
import { APP_STATE_CONTEXT_ID } from './_state/app-state-context-id';
16+
import { AppState } from './_state/app-state.type';
1617
import { THEME_STORAGE_KEY, useCSSTheme } from './_state/use-css-theme';
1718
import { OLD_APP_STATE_CONTEXT_ID } from './constants';
1819
import globalStyles from './global.css?inline';
@@ -27,9 +28,17 @@ export default component$(() => {
2728
*/
2829
useStyles$(globalStyles);
2930

30-
const appState = useAppStateProvider();
31+
const appState = useStore<AppState>({
32+
mode: 'light',
33+
isSidebarOpened: false,
34+
featureFlags: {
35+
showFluffy: import.meta.env.DEV,
36+
},
37+
});
38+
39+
useContextProvider(APP_STATE_CONTEXT_ID, appState);
3140

32-
useVisibleTask$(() => {
41+
useVisibleTask$(async () => {
3342
const userStoredTheme = localStorage.getItem(THEME_STORAGE_KEY);
3443
if (userStoredTheme) {
3544
appState.mode = userStoredTheme === 'dark' ? 'dark' : 'light';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getHighlighter, type Highlighter } from 'shiki';
2+
3+
let highlighter: Highlighter;
4+
export async function getOrCreateHighlighter() {
5+
if (highlighter) {
6+
return highlighter;
7+
}
8+
highlighter = await getHighlighter({ theme: 'css-variables' });
9+
return highlighter;
10+
}

apps/website/src/routes/docs/headless/(components)/tabs/highlight.tsx renamed to apps/website/src/routes/docs/_components/highlight/highlight.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { QwikIntrinsicElements, component$, useSignal, useTask$ } from '@builder.io/qwik';
22
import { OmitSignalClass } from '@qwik-ui/type-utils';
3-
import shiki from 'shiki';
3+
import { getOrCreateHighlighter } from './get-or-create-highlighter';
44

55
export type HighlightProps = OmitSignalClass<QwikIntrinsicElements['pre']> & {
66
code: string;
@@ -17,10 +17,8 @@ export const Highlight = component$(
1717
}: HighlightProps) => {
1818
const codeSig = useSignal('');
1919

20-
// const appState = useContext(APP_STATE_CONTEXT_ID);
21-
2220
useTask$(async function createHighlightedCode() {
23-
const highlighter = await shiki.getHighlighter({ theme: 'css-variables' });
21+
const highlighter = await getOrCreateHighlighter();
2422
let modifiedCode: string = code;
2523

2624
let partsOfCode = modifiedCode.split(splitCommentStart);

0 commit comments

Comments
 (0)