Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": ["packages/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.11.9",
"version": "0.12.1-alpha.0",
"command": {
"version": {
"message": "chore(release): publish %s"
Expand Down
2 changes: 1 addition & 1 deletion packages/apsara-icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@goto-company/icons",
"version": "0.11.9",
"version": "0.12.1-alpha.0",
"description": "Apsara icons",
"scripts": {
"build": "node scripts/build.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/apsara-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@goto-company/apsara",
"version": "0.11.9",
"version": "0.12.1-alpha.0",
"description": "A list of base components for apsara",
"author": "Praveen Yadav <[email protected]>",
"license": "Apache-2.0",
Expand Down
16 changes: 3 additions & 13 deletions packages/apsara-ui/src/DynamicList/DynamicList.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useEffect } from "react";
import React, { FC } from "react";
import DynamicList from "./index";
import FormBuilder from "../FormBuilder";
import Button from "../Button";
Expand All @@ -23,9 +23,7 @@ export const Form: FC = () => {

const meta = {
name: ["policies"],
disabled: (index: number) => {
return index === 0 || index === 2;
},
disabled: () => true,
fields: [
{
key: "account_type",
Expand Down Expand Up @@ -72,21 +70,13 @@ export const Form: FC = () => {
],
};

const [updateDisable, setUpdateDisable] = React.useState(false);

useEffect(() => {
setTimeout(() => {
setUpdateDisable(true);
}, 3000);
}, []);

const DynamicListContent = ({ form, meta }: any) => {
return (
<div>
<DynamicList
form={form}
meta={meta}
addBtnProps={{ disabled: updateDisable }}
removeBtnProps={{ onClick: () => console.log("Remove clicked") }}
addBtnText="Add another role"
/>
</div>
Expand Down
7 changes: 7 additions & 0 deletions packages/apsara-ui/src/DynamicList/DynamicList.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ export const DynamicListContainer = styled.div`
}

.form-dynamic-list__btn-remove {
background: none;
border: none;
padding: 0;
display: inline-flex;
color: red;
margin-left: 20px;
${baseButtonStyles}
:disabled {
opacity: 0.6;
}
}
`;
27 changes: 19 additions & 8 deletions packages/apsara-ui/src/DynamicList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ interface FormItemDynamicListProps {
add: () => void;
addBtnText: string;
addBtnProps?: ButtonHTMLAttributes<HTMLButtonElement>;
removeBtnProps?: ButtonHTMLAttributes<HTMLButtonElement>;
}

interface DynamicListProps {
form: any;
meta: any;
addBtnText?: string;
addBtnProps?: ButtonHTMLAttributes<HTMLButtonElement>;
removeBtnProps?: ButtonHTMLAttributes<HTMLButtonElement>;
}

const FormItemDynamicList = ({
Expand All @@ -31,6 +33,7 @@ const FormItemDynamicList = ({
formListfields,
addBtnText,
addBtnProps,
removeBtnProps,
}: FormItemDynamicListProps) => {
// ? We need to do this because we can't set value and initialValue for form.list items from config
useEffect(() => {
Expand Down Expand Up @@ -69,14 +72,21 @@ const FormItemDynamicList = ({
return (
<div key={field.key} className="form-dynamic-list__item">
<FormBuilder.Items index={index} form={form} meta={{ ...meta, fields }} />
<Icon
<button
type="button"
role="presentation"
className="form-dynamic-list__btn-remove"
name="remove"
active
color="#dc3545"
disabled={isDisabled}
onClick={() => !isDisabled && remove(field.name)}
/>
disabled={isDisabled || removeBtnProps?.disabled}
onClick={() => !isDisabled && !removeBtnProps?.disabled && remove(field.name)}
{...removeBtnProps}
>
<Icon
name="remove"
active
color="#dc3545"
disabled={isDisabled || removeBtnProps?.disabled}
/>
</button>
</div>
);
})}
Expand All @@ -96,7 +106,7 @@ const FormItemDynamicList = ({
);
};

export const DynamicList = ({ form, meta, addBtnText = "Add", addBtnProps }: DynamicListProps) => {
export const DynamicList = ({ form, meta, addBtnText = "Add", addBtnProps, removeBtnProps }: DynamicListProps) => {
return (
<List name={meta.name}>
{(formListfields, { add, remove }) => (
Expand All @@ -108,6 +118,7 @@ export const DynamicList = ({ form, meta, addBtnText = "Add", addBtnProps }: Dyn
formListfields={formListfields}
addBtnText={addBtnText}
addBtnProps={addBtnProps}
removeBtnProps={removeBtnProps}
/>
)}
</List>
Expand Down