Skip to content

Commit

Permalink
feat(docs): add live code tab layout component
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Aug 31, 2024
1 parent 9badd88 commit 4e5021c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
36 changes: 36 additions & 0 deletions packages/docs/src/components/live-code-tab-layout.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
// See https://astro-live-code.vercel.app/guides/customization/
//
// Layouts can be specified for a specific code block by adding a layout attribute to the code block:
// ```tsx layout="~/components/live-code-tab-layout.astro"
import { Tabs, TabItem } from '@astrojs/starlight/components';
---

<Tabs>
<TabItem label="Preview" >
<div class="example-container">
<slot name="example" />
</div>
</TabItem>
<TabItem label="Code">
<slot name="code" />
</TabItem>
</TabItem>

<style>
.live-code-layout {
display: flex;
flex-direction: column;
}

.example-container {
display: flex;
justify-content: center;
align-items: center;
padding: 2.5rem;
background: var(--ec-frm-edBg, var(--astro-code-color-background));
border-style: solid;
border-width: var(--ec-brdWd, 1px);
border-color: var(--ec-brdCol, var(--sl-color-gray-5));
}
</style>
21 changes: 18 additions & 3 deletions packages/docs/src/content/docs/customization/theme.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function AdvancedFilter({ schema }) {

You can override existing theme by replacing them with your own custom components or templates.

```tsx live wrapper="~/components/mui-theme-wrapper.tsx"
```tsx live wrapper="~/components/mui-theme-wrapper.tsx" layout="~/components/live-code-tab-layout.astro"
import { filterTheme } from "@fn-sphere/theme-mui-material";
import { Button } from "@mui/material";
import {
Expand All @@ -51,8 +51,9 @@ import {
useFilterRule,
useFilterGroup,
useView,
createFilterGroup,
createSingleFilter,
} from "@fn-sphere/filter";
import { Fragment } from "react";

const customTheme = {
...filterTheme,
Expand Down Expand Up @@ -113,8 +114,22 @@ const customTheme = {
},
};

const presetRule = createFilterGroup({
op: "and",
conditions: [
createSingleFilter(),
createFilterGroup({
op: "or",
conditions: [createSingleFilter(), createSingleFilter()],
}),
],
});

export default function AdvancedFilter({ schema }) {
const { predicate, context } = useFilterSphere({ schema });
const { predicate, context } = useFilterSphere({
schema,
defaultRule: presetRule,
});
return (
<FilterSphereProvider context={context} theme={customTheme}>
<FilterBuilder />
Expand Down

0 comments on commit 4e5021c

Please sign in to comment.