Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codesandbox examples for charting demos #987

Merged
merged 37 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dd68a29
initial effort
theiliad Mar 5, 2020
6ec0736
Merge branch 'master' of github.com:carbon-design-system/carbon-websi…
theiliad Mar 5, 2020
7c5c499
Merge branch 'master' into codesandbox-dataviz
theiliad Mar 5, 2020
59dbe60
Merge branch 'master' into codesandbox-dataviz
theiliad Mar 6, 2020
59806b6
Merge branch 'master' into codesandbox-dataviz
theiliad Mar 9, 2020
5d0e2a7
add dynamic demos to basic charts
theiliad Apr 9, 2020
c4c8869
Merge branch 'master' of github.com:carbon-design-system/carbon-websi…
theiliad Apr 9, 2020
0669dc5
Merge branch 'master' of github.com:carbon-design-system/carbon-websi…
theiliad Jun 5, 2020
a152988
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 5, 2020
f9eb9b1
update charting package version, optimize demo components
theiliad Jun 5, 2020
c10e8cf
Merge branch 'codesandbox-dataviz' of github.com:theiliad/carbon-webs…
theiliad Jun 5, 2020
18aa499
fix lint error
theiliad Jun 8, 2020
f513625
update @carbon/charts to 0.32.3
theiliad Jun 9, 2020
1defb65
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 9, 2020
31b1e59
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 9, 2020
076e799
Merge branch 'master' into codesandbox-dataviz
tw15egan Jun 9, 2020
ce03c2d
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 10, 2020
dab52f9
add image alt tags to dataviz chart types page
theiliad Jun 10, 2020
52a7a1e
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 11, 2020
e606862
Merge branch 'master' of github.com:carbon-design-system/carbon-websi…
theiliad Jun 11, 2020
483dde1
Merge branch 'master' of github.com:carbon-design-system/carbon-websi…
theiliad Jun 12, 2020
1ace04a
Merge branch 'master' of github.com:carbon-design-system/carbon-websi…
theiliad Jun 12, 2020
9bd44fb
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 12, 2020
1ed2c49
Merge branch 'codesandbox-dataviz' of github.com:theiliad/carbon-webs…
theiliad Jun 12, 2020
94b2702
update yarn.lock
theiliad Jun 12, 2020
5f3fb27
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 12, 2020
07990b3
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 15, 2020
82388ad
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 16, 2020
df93656
fix styling issues
theiliad Jun 16, 2020
d77fe25
styling fixes
theiliad Jun 22, 2020
a2c3aa8
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 22, 2020
15f2d99
undo overview-card tag height change
theiliad Jun 22, 2020
d34c8f7
Merge branch 'codesandbox-dataviz' of github.com:theiliad/carbon-webs…
theiliad Jun 22, 2020
2a31fac
move resources below anchor links for basic charts page
theiliad Jun 22, 2020
87f4d6b
Merge branch 'master' into codesandbox-dataviz
theiliad Jun 22, 2020
1145a1e
final touch on CodeBar
theiliad Jun 22, 2020
4b8bd93
Merge branch 'codesandbox-dataviz' of github.com:theiliad/carbon-webs…
theiliad Jun 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"carbon-components-react": "^7.14.0"
},
"dependencies": {
"@carbon/charts": "^0.28.1",
"@carbon/charts-react": "^0.28.1",
"@carbon/charts": "^0.32.8",
"@carbon/charts-react": "^0.32.8",
"@carbon/elements": "^10.14.0",
"@carbon/icons": "^10.13.0",
"@carbon/icons-react": "^10.13.0",
Expand Down
16 changes: 11 additions & 5 deletions src/components/ComponentDemo/Code/CodeBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ const StorybookLink = ({ framework, url }) => (
const CodeBar = ({ src, code, links }) => {
const sandboxUrl = useCodesandbox(code);
const storybookLinks = Object.entries(links);
const shouldShowCopyButton = !src && code;

Copy link
Contributor

@vpicone vpicone Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subjective alert Do you mind moving this into a single, affirmative boolean. Just to clarify the intent a bit we can avoid chaining shortcuts. Not sure how you would have known this, it should be codified in an eslint rule.

return (
<div className={codeBar}>
<div className={linkList}>
<a target="_blank" rel="noopener noreferrer" href={sandboxUrl}>
CodeSandbox <Launch16 />
</a>
{sandboxUrl && (
<a target="_blank" rel="noopener noreferrer" href={sandboxUrl}>
CodeSandbox <Launch16 />
</a>
)}
{storybookLinks.map(([framework, url]) => (
<StorybookLink key={framework} framework={framework} url={url} />
))}
</div>
{src ? (

{src && (
<a
target="_blank"
rel="noopener noreferrer"
Expand All @@ -42,7 +46,9 @@ const CodeBar = ({ src, code, links }) => {
>
<Launch16 />
</a>
) : (
)}

{shouldShowCopyButton && (
<CopyButton
className={cx(button, copyButton)}
onClick={() => {
Expand Down
4 changes: 4 additions & 0 deletions src/components/ComponentDemo/Code/useCodesandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const getIndex = ({ code = '' }) => {
const useCodesandbox = (code) => {
const { current: originalCode } = useRef(code);
const url = useMemo(() => {
if (!originalCode) {
return null;
}

const indexContent = getIndex({ code: originalCode });

const parameters = getParameters({
Expand Down
73 changes: 73 additions & 0 deletions src/components/data-visualization/AllDemos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react';

import * as ChartComponents from '@carbon/charts-react';

import H2 from 'gatsby-theme-carbon/src/components/markdown/H2';
import CodeBar from '../ComponentDemo/Code/CodeBar.js';

import demoGroups from '../../data/data-visualization';

const generateHeadingID = (title) =>
title
.split(' ')
.map((t) => t.toLowerCase())
.join('-');

const AllDemos = () => (
<>
{demoGroups.map((demoGroup) => (
<>
<H2>{demoGroup.title}</H2>

{demoGroup.description && (
<div className="bx--row">
<div className="bx--col-sm-4 bx--col-md-8 bx--col-lg-8">
<p className="dataviz-copy">{demoGroup.description}</p>
</div>
</div>
)}

{demoGroup.demos.map((demo) => {
const DemoComponent = ChartComponents[demo.chartType.vanilla];
return (
<>
{demo.description && (
<div className="bx--row">
<div className="bx--col-sm-4 bx--col-md-8 bx--col-lg-8">
<p className="dataviz-copy">{demo.description}</p>
</div>
</div>
)}
<div className="bx--row">
<div className="bx--col-sm-4 bx--col-md-8 bx--col-lg-8">
<div
className="chart-demo-wrapper"
id={generateHeadingID(demo.title)}
>
<div className="chart-demo">
<DemoComponent
data={demo.data}
options={demo.options}
style={{ maxWidth: 400 }}
/>
</div>
<CodeBar
links={{
React: demo.codesandbox.react,
Angular: `https://carbon-design-system.github.io/carbon-charts/angular/?path=/story/${demo.id}`,
Vue: demo.codesandbox.vue,
Vanilla: demo.codesandbox.vanilla,
}}
/>
</div>
</div>
</div>
</>
);
})}
</>
))}
</>
);

export default AllDemos;
Loading