Skip to content

Commit

Permalink
feat: display a badge in top of all samples when the theme is a draft (
Browse files Browse the repository at this point in the history
  • Loading branch information
deleonio authored Dec 21, 2023
2 parents c8e8011 + ec2a024 commit fc7fd33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/samples/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Navigate, Route, Routes, useSearchParams } from 'react-router-dom';
import { Route as MyRoute, Routes as MyRoutes } from './shares/types';

import { Option } from '@public-ui/components';
import { KolAlert } from '@public-ui/react';
import { KolAlert, KolBadge } from '@public-ui/react';
import { ROUTES } from './shares/routes';
import { Theme, THEME_OPTIONS } from './shares/theme';
import { isDraftTheme, Theme, THEME_OPTIONS } from './shares/theme';
import PackageJson from '@public-ui/components/package.json';
import { getTheme, getThemeName, setStorage, setTheme } from './shares/store';
import { Sidebar } from './components/Sidebar';
Expand Down Expand Up @@ -103,7 +103,7 @@ ROUTE_LIST.forEach((route) => {
export const App: FC = () => {
const routerLocation = useLocation();
const [searchParams, setSearchParams] = useSearchParams();
const theme = searchParams.get('theme') ?? getTheme();
const theme: Theme = (searchParams.get('theme') as Theme) ?? getTheme();
const hideMenus = searchParams.has('hideMenus');

setTheme(theme as Theme); // set for `getTheme` usages within the application
Expand Down Expand Up @@ -133,6 +133,7 @@ export const App: FC = () => {
)}

<div className="p-4" id="route-container">
{!hideMenus && isDraftTheme(theme) && <KolBadge className="mb-3" _label="DRAFT" _color="#db5461" />}
<Routes>
{ROUTE_TREE}
<Route path="*" element={<KolAlert _type="info">This code example has not been migrated yet - it&#39;s coming soon!</KolAlert>} />
Expand Down
4 changes: 4 additions & 0 deletions packages/samples/react/src/shares/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { SelectOption } from '@public-ui/components';

export type Theme = 'bmf' | 'default' | 'ecl-ec' | 'ecl-eu' | 'itzbund' | 'th' | 'unstyled';

const drafts: Theme[] = ['ecl-ec', 'ecl-eu', 'itzbund', 'th'];

export const isDraftTheme = (theme: Theme) => drafts.includes(theme);

export const isTheme = (value: unknown) => {
return (
typeof value === 'string' &&
Expand Down

0 comments on commit fc7fd33

Please sign in to comment.