on d760cbf help sign in
bridge/src/components/old/ValidatedSigil.js
75 lines 1.5 kB history raw
1import React from 'react';
2import PropTypes from 'prop-types';
4import { pour } from 'sigil-js';
5import * as ob from 'urbit-ob';
6import ReactSVGComponents from '../ReactSVGComponents';
8const isValidPatp = patp => {
9 let isValid = false;
10 try {
11 isValid = ob.isValidPatp(patp);
12 } catch (err) {
13 return isValid;
14 }
15 return isValid;
16};
18const ValidatedSigil = ({
19 className,
20 children,
21 style,
22 color,
23 patp,
24 size,
25 margin,
26 displayPass,
27 displayFailure,
28 focussed,
29 beenFocussed,
30}) => {
31 const colorStyle = styleSelector(displayPass, displayFailure, focussed);
33 return (
34 <div className={`${className}`} style={style}>
35 {isValidPatp(patp) ? (
36 pour({
37 patp: patp,
38 renderer: ReactSVGComponents,
39 size: size,
40 colorway: colorStyle,
41 margin: margin,
42 })
43 ) : (
44 <div
45 className={'bg-transparent'}
46 style={{
47 width: size,
48 height: size,
49 }}
50 />
51 )}
52 {children}
53 </div>
54 );
55};
57const styleSelector = (pass, fail, focus) => {
58 if (fail === true) return ['#FFFFFF', '#F8C134'];
59 if (pass === true) return ['#FFFFFF', '#2AA779'];
60 if (focus === true) return ['#FFFFFF', '#4330FC'];
61 return ['#FFFFFF', '#7F7F7F'];
62};
64ValidatedSigil.propTypes = {
65 className: PropTypes.string,
66 children: PropTypes.node,
67 style: PropTypes.object,
68};
70ValidatedSigil.defaultProps = {
71 className: '',
72 style: {},
73};
75export default ValidatedSigil;