Skip to content

Commit

Permalink
Release/0.7.0 (#98)
Browse files Browse the repository at this point in the history
* Table: allow ReactNode as table column label (#97)

* add customInputs (#95)

Co-authored-by: Iveta <[email protected]>
  • Loading branch information
piyalbasu and quietbits authored Feb 28, 2022
1 parent 2b4efff commit 6539aad
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 31 deletions.
2 changes: 1 addition & 1 deletion @stellar/design-system-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint-tsc": "tsc --noEmit"
},
"dependencies": {
"@stellar/design-system": "^0.6.0",
"@stellar/design-system": "^0.7.0",
"lodash": "^4.17.21",
"prism-react-renderer": "^1.2.1",
"react": "^17.0.2",
Expand Down
22 changes: 22 additions & 0 deletions @stellar/design-system-website/src/constants/details/inputs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Input, IconButton, Icon } from "@stellar/design-system";
import { ComponentDetails, ComponentDetailsId } from "types/types.d";

import { Field } from "./mocks";

export const inputs: ComponentDetails = {
id: ComponentDetailsId.inputs,
title: "Inputs",
Expand Down Expand Up @@ -88,6 +90,18 @@ export const inputs: ComponentDetails = {
/>,
],
},
{
title: "Input with custom input",
description: "",
component: [
<Input
customInput={<Field />}
id="input-12"
label="Label"
placeholder="Placeholder"
/>,
],
},
],
props: [
{
Expand Down Expand Up @@ -132,6 +146,14 @@ export const inputs: ComponentDetails = {
optional: true,
description: "Error message of the input",
},
{
prop: "customInput",
type: ["React.ReactNode"],
default: null,
optional: true,
description:
"Use a specific input rather than a generic HTML input (useful for Formik or otherwise controlled inputs)",
},
],
externalProps: {
link: "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// used to illustrate a Formik <Field /> in examples
export const Field = (props: any) => <input {...props} />;
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const tables: ComponentDetails = {
},
{
prop: "label",
type: ["string"],
type: ["string", "ReactNode"],
default: null,
optional: false,
description: "Column label",
Expand Down
59 changes: 47 additions & 12 deletions @stellar/design-system-website/src/constants/details/toggles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Toggle } from "@stellar/design-system";
import { ComponentDetails, ComponentDetailsId } from "types/types.d";

import { Field } from "./mocks";

export const toggles: ComponentDetails = {
id: ComponentDetailsId.toggles,
title: "Toggles",
Expand All @@ -16,24 +18,42 @@ export const toggles: ComponentDetails = {
title: "Default",
description: "",
component: [
<Toggle id="toggle-1" checked={false} onChange={() => {
// do nothing
}} />,
<Toggle id="toggle-2" checked={false} onChange={() => {
// do nothing
}} disabled />,
<Toggle
id="toggle-1"
checked={false}
onChange={() => {
// do nothing
}}
/>,
<Toggle
id="toggle-2"
checked={false}
onChange={() => {
// do nothing
}}
disabled
/>,
],
},
{
title: "Toggle on",
description: "",
component: [
<Toggle id="toggle-3" checked={true} onChange={() => {
// do nothing
}} />,
<Toggle id="toggle-4" checked={true} onChange={() => {
// do nothing
}} disabled />,
<Toggle
id="toggle-3"
checked={true}
onChange={() => {
// do nothing
}}
/>,
<Toggle
id="toggle-4"
checked={true}
onChange={() => {
// do nothing
}}
disabled
/>,
],
},
{
Expand Down Expand Up @@ -140,6 +160,13 @@ export const toggles: ComponentDetails = {
/>,
],
},
{
title: "Toggle with custom input",
description: "",
component: [
<Toggle customInput={<Field />} checked={true} id="toggle-13" />,
],
},
],
props: [
{
Expand Down Expand Up @@ -191,6 +218,14 @@ export const toggles: ComponentDetails = {
optional: true,
description: "Position of the label",
},
{
prop: "customInput",
type: ["React.ReactNode"],
default: null,
optional: true,
description:
"Use a specific input rather than a generic HTML input (useful for Formik or otherwise controlled inputs)",
},
],
externalProps: {
link: "",
Expand Down
2 changes: 1 addition & 1 deletion @stellar/design-system-website/src/generated/gitInfo.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default { commitHash: "f86f428" };
export default { commitHash: "2b4efff" };
2 changes: 1 addition & 1 deletion @stellar/design-system/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/design-system",
"version": "0.6.0",
"version": "0.7.0",
"author": "Stellar Development Foundation <[email protected]>",
"description": "Components for Stellar Development Foundation’s design system",
"license": "Apache-2.0",
Expand Down
15 changes: 13 additions & 2 deletions @stellar/design-system/src/components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from "react";
import React, { cloneElement } from "react";
import { FieldElement } from "../utils/FieldElement";
import { FieldNote } from "../utils/FieldNote";
import "./styles.scss";

interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
customInput?: React.ReactElement;
id: string;
label?: string | React.ReactNode;
leftElement?: string | React.ReactNode;
Expand All @@ -13,6 +14,7 @@ interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
}

export const Input: React.FC<InputProps> = ({
customInput,
id,
label,
leftElement,
Expand All @@ -26,6 +28,11 @@ export const Input: React.FC<InputProps> = ({
...(error ? ["Input--error"] : []),
].join(" ");

const baseInputProps = {
id,
"aria-invalid": !!error,
};

return (
<div className={`Input ${additionalClasses}`}>
{label && <label htmlFor={id}>{label}</label>}
Expand All @@ -38,7 +45,11 @@ export const Input: React.FC<InputProps> = ({
)}

<div className="Input__wrapper">
<input id={id} aria-invalid={!!error} {...props} />
{customInput ? (
cloneElement(customInput, { ...baseInputProps, ...props })
) : (
<input {...baseInputProps} {...props} />
)}
</div>

{rightElement && (
Expand Down
2 changes: 1 addition & 1 deletion @stellar/design-system/src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "./styles.scss";

interface TableColumnLabel {
id: string;
label: string;
label: string | React.ReactNode;
sortBy?: boolean;
}

Expand Down
32 changes: 20 additions & 12 deletions @stellar/design-system/src/components/Toggle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { cloneElement, useEffect, useState } from "react";
import "./styles.scss";

enum LabelPosition {
Expand All @@ -13,7 +13,8 @@ interface ToggleComponent {
interface ToggleProps extends React.InputHTMLAttributes<HTMLInputElement> {
id: string;
checked: boolean;
onChange: () => void;
customInput?: React.ReactElement;
onChange?: () => void;
disabled?: boolean;
labelOn?: string;
labelOff?: string;
Expand All @@ -23,6 +24,7 @@ interface ToggleProps extends React.InputHTMLAttributes<HTMLInputElement> {
export const Toggle: React.FC<ToggleProps> & ToggleComponent = ({
id,
checked,
customInput,
onChange,
disabled,
labelOn,
Expand All @@ -39,19 +41,25 @@ export const Toggle: React.FC<ToggleProps> & ToggleComponent = ({
" ",
);

const renderLabel = () => <span>{checked ? labelOn : labelOff}</span>;
const renderLabel = () =>
labelOn ? <span>{checked ? labelOn : labelOff ?? labelOn}</span> : null;

const baseInputProps = {
className: "Toggle__input",
type: "checkbox",
name: id,
id,
disabled,
};

return (
<label className={`Toggle ${additionalClasses}`} htmlFor={id}>
<input
className="Toggle__input"
type="checkbox"
name={id}
id={id}
checked={checkedValue}
onChange={onChange}
disabled={disabled}
/>
{customInput ? (
cloneElement(customInput, { ...baseInputProps })
) : (
<input checked={checkedValue} onChange={onChange} {...baseInputProps} />
)}

{labelPosition === LabelPosition.left ? renderLabel() : null}
<div className="Toggle__track" />
{labelPosition === LabelPosition.right ? renderLabel() : null}
Expand Down

0 comments on commit 6539aad

Please sign in to comment.