Skip to content

Commit

Permalink
Merge pull request #62 from perimetre/3.4.9
Browse files Browse the repository at this point in the history
3.4.9
  • Loading branch information
adarleyjrr authored Apr 18, 2022
2 parents 4136be1 + a94d00e commit e0f44ff
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [3.4.9] 2022-04-14

### Added

- Added option to set values of type `React.ReactNode`, in addition to currently accepted type `string`, to `label` prop of `CheckboxRadioInput` component.

## [3.4.8] 2022-03-07

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@perimetre/ui",
"description": "A component library made by @perimetre",
"version": "3.4.8",
"version": "3.4.9",
"repository": {
"type": "git",
"url": "git+https://github.com/perimetre/ui.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
// also exported from '@storybook/react' if you can deal with breaking changes in 6.1
import { Meta, Story } from '@storybook/react/types-6-0';
import React from 'react';
Expand All @@ -6,6 +7,18 @@ import classnames from 'classnames';
import { CheckboxRadioInput, CheckboxRadioInputProps } from '.';
import { puiColorClassnameMap } from '../../storybookMappers';

const labels = {
string: 'Label text content',
jsx: (
<p>
Agree with{' '}
<a href="#" target="_blank" rel="noreferrer noopener" className="pui-link">
terms
</a>
</p>
)
};

export default {
title: 'Components/Inputs/Checkbox Radio',
component: CheckboxRadioInput,
Expand All @@ -21,7 +34,16 @@ export default {
}
},
label: {
defaultValue: 'Label content'
defaultValue: labels.string,
options: Object.keys(labels),
mapping: labels,
control: {
type: 'select',
labels: {
string: 'Text label',
jsx: 'JSX component'
}
}
},
defaultChecked: {
control: {
Expand Down Expand Up @@ -70,6 +92,11 @@ NoLabel.args = {
label: undefined
};

export const JSXLabel = Template.bind({});
JSXLabel.args = {
label: labels.jsx
};

export const WithHelp = Template.bind({});
WithHelp.args = {
help: 'You can also have a help text'
Expand Down
24 changes: 18 additions & 6 deletions src/components/CheckboxRadioInput/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,12 @@
@apply h-6 w-6 border-2;
}

/* Style the checkbox label */
/* Style the checkbox label within any html tag */
.pui-checkbox-label,
.pui-radio-label {
/* Adds pointer cursor */
/* Don't allow selection */
/* Make it flex */
/* Align everything vertically */
@apply cursor-pointer select-none flex items-center;
@apply flex items-center;

/* The input inside the label */
input {
Expand All @@ -157,12 +155,26 @@
}
}

/* The label text wraper */
/* The label content wraper */
span {
/* Adds a margin left */
@apply ml-2;
}
}

/* Style the checkbox label within label tag (entire label tag clickable) */
.pui-checkbox-label-clickable,
.pui-radio-label-clickable {
/* Apply the base checkbox/radio styling */
/* Adds pointer cursor */
/* Don't allow selection */
@apply pui-checkbox-label pui-radio-label cursor-pointer select-none;

/* The label text content wraper */
span {
/* Its color should use the 900 shade */
/* Adds a little bit of letter spacing(just like text input label) */
@apply ml-2 text-pui-paragraph-900 tracking-wide;
@apply text-pui-paragraph-900 tracking-wide;
}
}
}
16 changes: 12 additions & 4 deletions src/components/CheckboxRadioInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export type CheckboxRadioInputProps = React.DetailedHTMLProps<
*/
indeterminate?: boolean;
/**
* If provided, displays a label above the input
* If provided, displays a label above the input. If value provided is of type string, the content will be parsed as rich text/html content
*/
label?: string;
label?: React.ReactNode;
/**
* If provided, displays a help text under the input
*/
Expand Down Expand Up @@ -95,16 +95,24 @@ export const CheckboxRadioInput: React.FC<CheckboxRadioInputProps> = ({
</div>
);

return label ? (
return typeof label === 'string' ? (
<div>
<label className={`${type === 'checkbox' ? 'pui-checkbox-label' : 'pui-radio-label'}`}>
<label className={`${type === 'checkbox' ? 'pui-checkbox-label-clickable' : 'pui-radio-label-clickable'}`}>
{input}
<span>
<HTMLParsedContent content={label} className="max-w-none" />
</span>
</label>
{bottom}
</div>
) : label ? (
<div>
<div className={`${type === 'checkbox' ? 'pui-checkbox-label' : 'pui-radio-label'}`}>
{input}
<span>{label}</span>
</div>
{bottom}
</div>
) : (
<div>
<span>{input}</span>
Expand Down

0 comments on commit e0f44ff

Please sign in to comment.