-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/icon-picker-typescript-conversion
- Loading branch information
Showing
11 changed files
with
360 additions
and
133 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BaseControl } from '@wordpress/components'; | ||
import { ColorPalette } from '@wordpress/block-editor'; | ||
import { useInstanceId } from '@wordpress/compose'; | ||
|
||
interface ColorSettingProps { | ||
/** | ||
* If this property is added, a label will be generated using label property as the content. | ||
*/ | ||
label?: string, | ||
|
||
/** | ||
* If true, the label will only be visible to screen readers. | ||
*/ | ||
hideLabelFromVision?: boolean, | ||
|
||
/** | ||
* If this property is added, a help text will be generated using help property as the content. | ||
*/ | ||
help?: string, | ||
|
||
/** | ||
* If no className is passed only components-base-control is used. | ||
*/ | ||
className?: string, | ||
|
||
/** | ||
* Whether to allow custom color or not. | ||
*/ | ||
disableCustomColors?: boolean, | ||
|
||
/** | ||
* currently active value. | ||
*/ | ||
value?: string, | ||
|
||
/** | ||
* Whether the palette should have a clearing button or not. | ||
*/ | ||
clearable?: boolean, | ||
|
||
/** | ||
* Array with the colors to be shown. | ||
*/ | ||
colors: Array<Color>, | ||
|
||
/** | ||
* Callback called when a color is selected. | ||
*/ | ||
onChange: Function, | ||
} | ||
|
||
interface Color { | ||
/** | ||
* Color name. | ||
*/ | ||
name: string, | ||
|
||
/** | ||
* Color hex code. | ||
*/ | ||
color: string, | ||
} | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const ColorSetting: React.FC<ColorSettingProps> = ({ | ||
label= '', | ||
help = '', | ||
className = '', | ||
hideLabelFromVision = false, | ||
colors, | ||
value = '', | ||
onChange, | ||
disableCustomColors = false, | ||
clearable = true, | ||
}) => { | ||
const instanceId = useInstanceId(ColorSetting); | ||
const id = `color-settings-${instanceId}`; | ||
|
||
return ( | ||
<BaseControl | ||
id={id} | ||
label={label} | ||
help={help} | ||
className={className} | ||
hideLabelFromVision={hideLabelFromVision} | ||
> | ||
<ColorPalette | ||
colors={colors} | ||
value={value} | ||
onChange={onChange} | ||
disableCustomColors={disableCustomColors} | ||
clearable={clearable} | ||
/> | ||
</BaseControl> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Counter | ||
|
||
The `Counter` component let's you use circular progress bar with two props - `count` and `limit`. | ||
|
||
This also exposes another component named `CircularProgressBar`, which can be used when we don't want the text annotation and just the SVG illustration. | ||
|
||
## Usage | ||
|
||
```js | ||
import { Counter, CircularProgressBar } from '@10up/block-components'; | ||
|
||
function MyComponent( props ) { | ||
|
||
return ( | ||
<> | ||
<Counter | ||
count={text.length} | ||
limit={20} | ||
/> | ||
|
||
<CircularProgressBar | ||
percentage={(text.length / 20) * 100} | ||
/> | ||
</> | ||
); | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
#### Counter | ||
|
||
| Name | Type | Default | isRequired | Description | | ||
| ---------------- | ---------- | ---------- | --------------------- | ---------------------------------------------------------------------- | | ||
| `count` | `number` | - | `Yes` | Current count of the counter. | | ||
| `limit` | `number` | - | `Yes` | Max limit of the counter. | | ||
|
||
#### CircularProgressBar | ||
|
||
| Name | Type | Default | isRequired | Description | | ||
| ---------------- | ---------- | ---------- | --------------------- | ---------------------------------------------------------------------- | | ||
| `percentage` | `number` | - | `Yes` | Elapsed percentage of the timer. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.