Skip to content

Commit

Permalink
Add src attribute to CSS and GeSHi blocks. Issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed May 15, 2021
1 parent 077f2ba commit f8039aa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
39 changes: 28 additions & 11 deletions blocks/oik-css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Uses the logic for the [bw_css] shortcode
*
* @copyright (C) Copyright Bobbing Wide 2018-2020
* @copyright (C) Copyright Bobbing Wide 2018-2021
* @author Herb Miller @bobbingwide
*/
import './style.scss';
Expand Down Expand Up @@ -80,15 +80,17 @@ export default registerBlockType(
// Set for each piece of dynamic data used in your block
attributes: {

css: {
type: 'string',

},
text: {
type: 'string',
default: '',
},

css: {
type: 'string',
},
text: {
type: 'string',
default: '',
},
src: {
type: 'string',
default: '',
}
},
example: {
attributes: {
Expand Down Expand Up @@ -139,6 +141,10 @@ export default registerBlockType(
const onChangeCSS = ( value ) => {
setAttributes( { css: value } );
};

const onChangeSrc = ( value ) => {
setAttributes( { src: value } );
}

return (
<Fragment>
Expand All @@ -147,14 +153,25 @@ export default registerBlockType(
<PanelBody>
<TextareaControl label="Text" value={attributes.text} onChange={onChangeText} />
</PanelBody>
<PanelBody>
<PanelRow>
<TextControl
label={ __( 'Source file: ID, URL or path' ) }
value={ attributes.src }
onChange={ onChangeSrc }

/>

</PanelRow>
</PanelBody>
</InspectorControls>
<Fragment>

<div className="wp-block-oik-css-css " key="css-input">
<PlainText
id={inputId}
value={attributes.css}
placeholder={__('Write CSS')}
placeholder={__('Write CSS or specify a source file.')}
onChange={onChangeCSS}
/>
</div>
Expand Down
22 changes: 20 additions & 2 deletions blocks/oik-geshi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Uses [bw_geshi] shortcode from oik-css plugin
*
* @copyright (C) Copyright Bobbing Wide 2018-2020
* @copyright (C) Copyright Bobbing Wide 2018-2021
* @author Herb Miller @bobbingwide
*/
import './style.scss';
Expand Down Expand Up @@ -97,6 +97,10 @@ export default registerBlockType(
content: {
type: 'string',
},
src: {
type: 'string',
default: ''
}


},
Expand Down Expand Up @@ -150,6 +154,9 @@ export default registerBlockType(
const onChangeContent = ( value ) => {
props.setAttributes( { content: value } );
};
const onChangeSrc = ( value ) => {
props.setAttributes( { src: value } );
}

/**
* Attempt a generic function to apply a change
Expand Down Expand Up @@ -188,6 +195,17 @@ export default registerBlockType(
onChange={ onChangeText }
/>
</PanelRow>
<PanelBody>
<PanelRow>
<TextControl
label={ __( 'Source file: ID, URL or path' ) }
value={ props.attributes.src }
onChange={ onChangeSrc }

/>

</PanelRow>
</PanelBody>

</PanelBody>

Expand All @@ -202,7 +220,7 @@ export default registerBlockType(
<div className="wp-block-oik-css-geshi wp-block-shortcode" key="content-input">
<PlainText
value={props.attributes.content}
placeholder={__('Write code')}
placeholder={__('Write code or specify a source file.')}
onChange={onChangeContent}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions examples/example-css-as-txt-file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p { color: red; }

0 comments on commit f8039aa

Please sign in to comment.