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

Add open with processing to examples #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions src/components/CopyButton.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.root {
position: absolute;
right: var(--gutter);
height: 32px;
padding: 6px 12px;
font-size: var(--text-small);
Expand Down
27 changes: 27 additions & 0 deletions src/components/OpenWithButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import classnames from 'classnames';

import ProcessingIcon from '../images/logo-processing.svg';

import * as css from './CopyButton.module.css';

const OpenWithButton = ({ text }) => {
return (
<a
href={`pde://sketch/base64/${stringToBase64(text)}`}
type="button"
className={classnames(css.root)}
>
<ProcessingIcon /> {'Open With Processing'}
</a>
)
}

export default OpenWithButton;

function stringToBase64(str) {
if (typeof Buffer !== 'undefined') {
return Buffer.from(str).toString('base64');
}
return btoa(str);
}
24 changes: 24 additions & 0 deletions src/components/OpenWithButton.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.root {
height: 32px;
padding: 6px 12px;
font-size: var(--text-small);
font-weight: bold;
color: var(--darkgray);
cursor: pointer;
fill: var(--darkgray);

& svg {
height: 12px;
width: auto;
}
}

.root:hover {
color: var(--darkergray);
fill: var(--darkergray);
}

.root:active {
color: var(--processing-blue-mid);
fill: var(--processing-blue-mid);
}
6 changes: 5 additions & 1 deletion src/components/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classnames from 'classnames';

import Button from './Button';
import CopyButton from './CopyButton';
import OpenWithButton from './OpenWithButton';

import { useHighlight } from '../hooks';
import { escapeHtml } from '../utils';
Expand Down Expand Up @@ -40,7 +41,10 @@ const Tabs = ({ pdes, className }) => {
[css.activeCode]: pde.name === active
})}
key={key}>
<CopyButton text={pde.code} />
<div className={css.actions}>
<CopyButton text={pde.code} />
<OpenWithButton text={pde.code} />
</div>
<pre className={css.codeBlock}>
<code
dangerouslySetInnerHTML={{
Expand Down
5 changes: 5 additions & 0 deletions src/components/Tabs.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@
padding-bottom: var(--gutter-double);
white-space: break-spaces;
}

.actions{
position: absolute;
right: var(--gutter);
}