-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support tabs in playground component
- Loading branch information
Showing
10 changed files
with
10,521 additions
and
10,068 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,54 +1,72 @@ | ||
import { styled, Tabs } from "@odpf/apsara"; | ||
import dynamic from "next/dynamic"; | ||
import React from "react"; | ||
|
||
import { styled } from '@stitches/react' | ||
import dynamic from 'next/dynamic' | ||
import React from 'react' | ||
const DynamicLive = dynamic(() => import("./live"), { | ||
ssr: false, | ||
loading: () => ( | ||
<div style={{ padding: "32px 16px", fontSize: "12px", borderRadius: "6px", border: "1px solid #ededed" }}> | ||
loading... | ||
</div> | ||
), | ||
}); | ||
|
||
const DynamicLive = dynamic(() => import('./live'), { | ||
ssr: false, | ||
loading: () => ( | ||
<div style={{ padding: '32px 16px', fontSize: "12px", borderRadius: "6px", | ||
border: '1px solid #ededed' }}> | ||
loading... | ||
</div> | ||
), | ||
}) | ||
export type Tab = { | ||
name: string; | ||
code: string; | ||
}; | ||
|
||
export type PlaygroundProps = { | ||
title?: React.ReactNode | string | ||
desc?: React.ReactNode | string | ||
code: string | ||
scope: { | ||
[key: string]: any | ||
} | ||
} | ||
title?: React.ReactNode | string; | ||
desc?: React.ReactNode | string; | ||
code: string; | ||
tabs: Tab[]; | ||
scope: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
|
||
const defaultProps = { | ||
code: '', | ||
scope: {}, | ||
} | ||
code: "", | ||
tabs: [] as Tab[], | ||
scope: {}, | ||
}; | ||
|
||
const StyledPlayground = styled("div", { | ||
borderRadius: "$2", | ||
border: '1px solid $gray4' | ||
}) | ||
borderRadius: "$2", | ||
border: "1px solid $gray4", | ||
}); | ||
|
||
const Playground: React.FC<PlaygroundProps> = React.memo( | ||
({ | ||
code: inputCode, | ||
scope, | ||
}: PlaygroundProps & typeof defaultProps) => { | ||
|
||
const code = inputCode.trim() | ||
return ( | ||
<> | ||
<StyledPlayground> | ||
<DynamicLive code={code} scope={scope} /> | ||
</StyledPlayground> | ||
</> | ||
) | ||
}, | ||
) | ||
({ code, tabs, scope }: PlaygroundProps & typeof defaultProps) => { | ||
if (code) { | ||
return ( | ||
<StyledPlayground> | ||
<DynamicLive code={code} scope={scope} /> | ||
</StyledPlayground> | ||
); | ||
} | ||
return ( | ||
<StyledPlayground> | ||
<Tabs defaultValue={tabs[0]?.name} > | ||
<Tabs.List css={{background: "transparent", p: "$4", gap: "$3", borderBottom: "1px solid $gray4"}}> | ||
{tabs.map((tab) => ( | ||
<Tabs.Trigger value={tab.name} key={tab.name}> | ||
{tab.name} | ||
</Tabs.Trigger> | ||
))} | ||
</Tabs.List> | ||
{tabs.map((tab) => ( | ||
<Tabs.Content value={tab.name} key={tab.name}> | ||
<DynamicLive code={tab.code} scope={scope} /> | ||
</Tabs.Content> | ||
))} | ||
</Tabs> | ||
</StyledPlayground> | ||
); | ||
}, | ||
); | ||
|
||
Playground.defaultProps = defaultProps | ||
Playground.displayName = 'Playground' | ||
export default Playground | ||
Playground.defaultProps = defaultProps; | ||
Playground.displayName = "Playground"; | ||
export default Playground; |
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
Oops, something went wrong.
209625a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
apsara – ./
apsara-amber.vercel.app
apsara-git-main-odpf.vercel.app
apsara-odpf.vercel.app