Skip to content

Commit

Permalink
feat: Render and style SVG drawings #69
Browse files Browse the repository at this point in the history
  • Loading branch information
lo5 committed Aug 2, 2022
1 parent 25f3ef4 commit 5c97cc9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
7 changes: 5 additions & 2 deletions web/src/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Separator } from './separator';
import { Slider } from './slider';
import { Spinbox } from './spinbox';
import { Spinner } from './spinner';
import { SVGBox } from './svg';
import { Table } from './table';
import { TagPicker } from './tag_picker';
import { Textbox } from './textbox';
Expand Down Expand Up @@ -82,10 +83,12 @@ export const XBox = ({ context, box }: BoxProps) => { // recursive
return <Rating context={context} box={box} />
} else if (modes.has('progress')) {
return <ProgressBar context={context} box={box} />
} else if (modes.has('spinner')) {
return <Spinner context={context} box={box} />
} else if (modes.has('separator')) {
return <Separator context={context} box={box} />
} else if (modes.has('spinner')) {
return <Spinner context={context} box={box} />
} else if (modes.has('svg')) {
return <SVGBox context={context} box={box} />
} else if (modes.has('info') || modes.has('success') || modes.has('warning') || modes.has('critical') || modes.has('blocked') || modes.has('error')) {
return <Banner context={context} box={box} />
} else if (modes.has('table')) {
Expand Down
3 changes: 2 additions & 1 deletion web/src/heuristics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const knownModes = [
'row', 'col', 'tab', 'md', 'button', 'menu', 'radio', 'check', 'toggle', 'password',
'text', 'range', 'number', 'time', 'date', 'day', 'week', 'month', 'tag', 'color',
'rating', 'table', 'file', 'progress', 'spinner', 'separator', 'image', 'web',
'info', 'success', 'warning', 'critical', 'blocked', 'error'
'info', 'success', 'warning', 'critical', 'blocked', 'error', 'svg',
]

const readonlyBoxes = [
Expand All @@ -211,6 +211,7 @@ const readonlyBoxes = [
'error',
'image',
'web',
'svg',
]

const hasNoMode = (modes: Set<S>): B => { // TODO PERF speed up
Expand Down
27 changes: 27 additions & 0 deletions web/src/svg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 H2O.ai, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { css } from './css';
import { BoxProps } from './ui';

export const SVGBox = ({ box }: BoxProps) => {
const { text, style } = box
return (
<div className={css(style)} dangerouslySetInnerHTML={{ __html: text ?? '' }} />
)
}




0 comments on commit 5c97cc9

Please sign in to comment.