|
| 1 | +/** |
| 2 | + * External dependencies |
| 3 | + */ |
| 4 | +import { i18n } from 'stackable' |
| 5 | + |
| 6 | +/** |
| 7 | + * Internal dependencies |
| 8 | + */ |
| 9 | +import { toPng } from 'html-to-image' |
| 10 | + |
| 11 | +/** |
| 12 | + * WordPress dependencies |
| 13 | + */ |
| 14 | +import { sprintf, __ } from '@wordpress/i18n' |
| 15 | +import { useRef, useState } from '@wordpress/element' |
| 16 | +import { Icon, download as downloadIcon } from '@wordpress/icons' |
| 17 | +import { Button } from '@wordpress/components' |
| 18 | +import { isDarkColor } from '~stackable/util' |
| 19 | + |
| 20 | +export { default as StyleGuidePopover } from './popover' |
| 21 | + |
| 22 | +// TODO: This is not yet finished |
| 23 | +const StyleGuide = () => { |
| 24 | + const styleGuideRef = useRef( null ) |
| 25 | + |
| 26 | + return ( |
| 27 | + <> |
| 28 | + <ExportButton printRef={ styleGuideRef } /> |
| 29 | + <div className="ugb-style-guide"> |
| 30 | + <div className="ugb-style-guide__content editor-styles-wrapper" ref={ styleGuideRef }> |
| 31 | + |
| 32 | + <h1 className="ugb-style-guide__section-title">{ __( 'Colors', i18n ) }</h1> |
| 33 | + <h2 className="ugb-style-guide__section-subheading">{ __( 'Color Palette', i18n ) }</h2> |
| 34 | + <div className="ugb-style-guide__columns ugb-style-guide__colors"> |
| 35 | + <div className="ugb-style-guide__column" style={ { backgroundColor: '#f00069' } }> |
| 36 | + <div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#f00069' ) ? '#fff' : '#000' } }> |
| 37 | + #F00069 |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + <div className="ugb-style-guide__column" style={ { backgroundColor: '#111' } }> |
| 41 | + <div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#111' ) ? '#fff' : '#000' } }> |
| 42 | + #111111 |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + <div className="ugb-style-guide__column" style={ { backgroundColor: '#222' } }> |
| 46 | + <div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#222' ) ? '#fff' : '#000' } }> |
| 47 | + #222222 |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + <div className="ugb-style-guide__column" style={ { backgroundColor: '#333' } }> |
| 51 | + <div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#333' ) ? '#fff' : '#000' } }> |
| 52 | + #333333 |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + <div className="ugb-style-guide__column" style={ { backgroundColor: '#444' } }> |
| 56 | + <div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#444' ) ? '#fff' : '#000' } }> |
| 57 | + #444444 |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + <div className="ugb-style-guide__column" style={ { backgroundColor: '#555' } }> |
| 61 | + <div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#555' ) ? '#fff' : '#000' } }> |
| 62 | + #555555 |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + <div className="ugb-style-guide__column" style={ { backgroundColor: '#666' } }> |
| 66 | + <div className="ugb-style-guide__color-label ugb-style-guide__label" style={ { color: isDarkColor( '#666' ) ? '#fff' : '#000' } }> |
| 67 | + #666666 |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + |
| 72 | + <h2 className="ugb-style-guide__section-subheading">{ __( 'Color Schemes', i18n ) }</h2> |
| 73 | + |
| 74 | + <h1 className="ugb-style-guide__section-title">{ __( 'Typography', i18n ) }</h1> |
| 75 | + <div className="ugb-style-guide__columns"> |
| 76 | + <div className="ugb-style-guide__column"> |
| 77 | + <h2 className="ugb-style-guide__section-subheading">{ __( 'Titles & Headings', i18n ) }</h2> |
| 78 | + <h1>{ __( 'Heading 1', i18n ) }</h1> |
| 79 | + <h2>{ __( 'Heading 2', i18n ) }</h2> |
| 80 | + <h3>{ __( 'Heading 3', i18n ) }</h3> |
| 81 | + <h4>{ __( 'Heading 4', i18n ) }</h4> |
| 82 | + <h5>{ __( 'Heading 5', i18n ) }</h5> |
| 83 | + <h6>{ __( 'Heading 6', i18n ) }</h6> |
| 84 | + <p>{ __( 'Paragraph', i18n ) }</p> |
| 85 | + </div> |
| 86 | + <div className="ugb-style-guide__column"> |
| 87 | + <h2 className="ugb-style-guide__section-subheading">{ __( 'Body Text', i18n ) }</h2> |
| 88 | + <p>Morning sunlight filters through city windows as familiar voices fill the room. The table is scattered with mugs and yesterday\’s news, while someone debates the best way to arrange the cushions. Laughter drifts from the kitchen, and plans for the day are made between sips of coffee and playful banter.</p> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + </> |
| 94 | + ) |
| 95 | +} |
| 96 | + |
| 97 | +export default StyleGuide |
| 98 | + |
| 99 | +const ExportButton = props => { |
| 100 | + const { printRef } = props |
| 101 | + const [ isExporting, setIsExporting ] = useState( false ) |
| 102 | + |
| 103 | + const handlePrint = () => { |
| 104 | + setIsExporting( true ) |
| 105 | + toPng( printRef.current, { cacheBust: true } ) |
| 106 | + .then( dataUrl => { |
| 107 | + const link = document.createElement( 'a' ) |
| 108 | + link.download = 'style-guide.png' |
| 109 | + link.href = dataUrl |
| 110 | + link.click() |
| 111 | + setIsExporting( false ) |
| 112 | + } ) |
| 113 | + .catch( err => { |
| 114 | + alert( sprintf( __( 'Error exporting style guide: %s', i18n ), err.message || err ) ) // eslint-disable-line no-alert |
| 115 | + setIsExporting( false ) |
| 116 | + } ) |
| 117 | + } |
| 118 | + |
| 119 | + return ( |
| 120 | + <Button |
| 121 | + className="ugb-style-guide__print-button" |
| 122 | + isSecondary |
| 123 | + onClick={ handlePrint } |
| 124 | + icon={ <Icon icon={ downloadIcon } /> } |
| 125 | + isBusy={ isExporting } |
| 126 | + disabled={ isExporting } |
| 127 | + > |
| 128 | + { __( 'Export', i18n ) } |
| 129 | + </Button> |
| 130 | + ) |
| 131 | +} |
0 commit comments