Skip to content

Commit

Permalink
Issue #34 - add numberposts range control
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Feb 2, 2020
1 parent defa815 commit 0d86678
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
11 changes: 3 additions & 8 deletions blocks/oik-content/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ const shortcode_attributes =
default: '',
},

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

parameters: {
parameters: {
type: 'string',
default: '',
},
Expand All @@ -25,8 +20,8 @@ const shortcode_attributes =
default: '.',
},

number_posts: {
type: 'string',
numberposts: {
type: 'integer',
default: 10,
}

Expand Down
19 changes: 9 additions & 10 deletions blocks/oik-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const {
TextControl,
TextareaControl,
SelectControl,
RangeControl,
} = wp.components;
const Fragment = wp.element.Fragment;
import { map, partial, has } from 'lodash';
Expand All @@ -37,6 +38,7 @@ import { map, partial, has } from 'lodash';

import {bw_shortcodes, getAttributes} from "./bw_shortcodes";
import {PostTypes} from "./post_type";
import{ NumberPosts } from './numberposts';

const edit= withInstanceId(
( { attributes, setAttributes, instanceId, isSelected } ) => {
Expand Down Expand Up @@ -75,7 +77,7 @@ const edit= withInstanceId(
}

const onChangeNumberPosts = ( value ) => {
setAttributes( { number_posts: value } );
setAttributes( { numberposts: value } );
}


Expand All @@ -92,20 +94,17 @@ const edit= withInstanceId(
onChange={partial( onChangeAttr, 'shortcode' )}
/>

<PostTypes value={ attributes.post_type } onChange={onChangePostType } />
<PostTypes value={ attributes.post_type } onChange={ onChangePostType } />
<RangeControl label="Number posts" value={ attributes.numberposts } onChange={ onChangeNumberPosts } min={-1} max={100} />
<TextControl value={ attributes.post_parent} onChange={ onChangePostParent } label="Post Parent" />

<TextareaControl label="Parameters"
<TextareaControl label="Advanced Parameters"
value={ attributes.parameters }
placeholder={ __( 'Enter your shortcode parameters' ) }
placeholder={ __( 'Enter your advanced shortcode parameters' ) }
onChange={onChangeParameters}
rows="1"
/>
<TextareaControl label="Content"
id={ inputId }
value={ attributes.content }
placeholder={ __( 'Enter your shortcode content' ) }
onChange={onChangeContent}
/>




Expand Down
4 changes: 0 additions & 4 deletions blocks/oik-content/number_posts.js

This file was deleted.

40 changes: 40 additions & 0 deletions blocks/oik-content/numberposts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Implements the NumberPosts control
*
* Usage:
* <NumberPosts value={ attributes.numberposts } onChange={onChangeNumberPosts} />
*
* @copyright (C) Copyright Bobbing Wide 2020
* @author Herb Miller @bobbingwide
*/
const { RangeControl} = wp.components;
const { Component } = wp.element;

export class NumberPosts extends Component {
constructor() {
super( ...arguments );
console.log( this );
}

render( ) {

return(
<RangeControl
label="Number Posts"
value={ this.props.numberposts }
onChange={ this.props.onChange }
min={ 1 }
max={ 100 }
allowRest={true}
/>
);
}
}








4 changes: 2 additions & 2 deletions oik-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,11 @@ function oik_blocks_register_dynamic_blocks() {
//, 'script' => null
, 'attributes' =>
[ 'shortcode' => [ 'type'=>'string' ]
,'content' => [ 'type' => 'string ']
, 'content' => [ 'type' => 'string ']
, 'parameters' => [ 'type' => 'string']
, 'post_type' => ['type' => 'string']
, 'post_parent' => ['type' => 'string']
, 'number_posts' => ['type' => 'string']
, 'numberposts' => ['type' => 'integer']

]
] );
Expand Down

0 comments on commit 0d86678

Please sign in to comment.