Skip to content

Commit 614fedf

Browse files
author
Mat Jones
committed
code cleanup per review
1 parent b32e966 commit 614fedf

File tree

5 files changed

+25
-46
lines changed

5 files changed

+25
-46
lines changed

src/assets/scss/6-components/molecules/_drag-and-drop-list-box.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
.c-drag-and-drop-list-box {
2-
&.-dragging-container {
3-
.c-button {
4-
display: none !important;
5-
}
6-
}
7-
82
.c-list-box__item {
93
&.-dragging {
104
@include box-shadow(0px, 7px, 20px, get-color-neutral("30"));

src/molecules/lists/drag-and-drop-list-box.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from "react";
2-
import DragAndDropListBox from "./drag-and-drop-list-box";
2+
import { DragAndDropListBox } from "./drag-and-drop-list-box";
33
import { ListBoxItem } from "./list-box";
44
import { Paragraph } from "../../atoms/typography/paragraph";
55

src/molecules/lists/drag-and-drop-list-box.tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
DroppableProvided,
1010
DroppableStateSnapshot,
1111
} from "react-beautiful-dnd";
12-
import { CollectionUtils } from "andculturecode-javascript-core";
12+
import { CollectionUtils, StringUtils } from "andculturecode-javascript-core";
1313
import uuid from "uuid";
1414
import {
1515
ListBoxProps,
@@ -38,7 +38,7 @@ const COMPONENT_CLASS = `${ListBoxBaseClassName} c-drag-and-drop-list-box`;
3838
// #region Interfaces
3939
// -------------------------------------------------------------------------------------------------
4040

41-
export interface DragAndDropListBoxProps<T extends any>
41+
export interface DragAndDropListBoxProps<T extends string | number = string>
4242
extends Omit<ListBoxProps<T>, "children" | "items"> {
4343
droppableId: string;
4444
items: Array<ListBoxItem<T>>;
@@ -51,14 +51,14 @@ export interface DragAndDropListBoxProps<T extends any>
5151
// #region Component
5252
// -------------------------------------------------------------------------------------------------
5353

54-
const DragAndDropListBox = <T extends any>(
54+
export const DragAndDropListBox = <T extends string | number = string>(
5555
props: DragAndDropListBoxProps<T>
5656
): ReactElement<ListBoxProps<T>> | null => {
5757
const items = props.items;
5858
const hasItems = CollectionUtils.hasValues(items);
5959

6060
// Short-circuit if no items in collection
61-
if (items != null && !hasItems) {
61+
if (!hasItems) {
6262
if (props.hideWhenNoItems) {
6363
return null;
6464
}
@@ -118,7 +118,7 @@ const DragAndDropListBox = <T extends any>(
118118
<React.Fragment>
119119
{itemProps.items.map((item: ListBoxItem<T>, index: number) => (
120120
<Draggable
121-
draggableId={`${item.id}`}
121+
draggableId={item.id.toString()}
122122
index={index}
123123
key={uuid.v4()}>
124124
{(
@@ -128,19 +128,19 @@ const DragAndDropListBox = <T extends any>(
128128
<div
129129
{...provided.draggableProps}
130130
{...provided.dragHandleProps}
131-
ref={provided.innerRef}
132131
className={`${ListBoxItemClassName} ${cssIsDragging(
133132
snapshot
134133
)}`}
134+
ref={provided.innerRef}
135135
style={provided.draggableProps.style}>
136136
<div className="-drag-handle">
137137
<Icon
138-
type={Icons.DragAndDrop}
139138
size={IconSizes.Large}
139+
type={Icons.DragAndDrop}
140140
/>
141141
</div>
142142
{// if
143-
item.label != null && (
143+
StringUtils.hasValue(item.label) && (
144144
<div
145145
className={`${ListBoxItemClassName}__label`}>
146146
{item.label}
@@ -153,7 +153,6 @@ const DragAndDropListBox = <T extends any>(
153153
{// if
154154
props.onActionClick != null && (
155155
<Button
156-
type={ButtonTypes.Button}
157156
cssClassName={`${ListBoxItemClassName}__action`}
158157
onClick={() =>
159158
props.onActionClick!(
@@ -162,7 +161,8 @@ const DragAndDropListBox = <T extends any>(
162161
)
163162
}
164163
size={ButtonSizes.Small}
165-
style={ButtonStyles.TertiaryAlt}>
164+
style={ButtonStyles.TertiaryAlt}
165+
type={ButtonTypes.Button}>
166166
{props.actionText ?? "Action"}
167167
</Button>
168168
)}
@@ -187,10 +187,10 @@ const DragAndDropListBox = <T extends any>(
187187
) => (
188188
<div
189189
{...provided.droppableProps}
190-
ref={provided.innerRef}
191190
className={`${COMPONENT_CLASS} ${cssIsDragging(
192191
snapshot
193-
)}`}>
192+
)}`}
193+
ref={provided.innerRef}>
194194
{// if
195195
hasItems && <DraggableItemList items={items} />}
196196
{provided.placeholder}
@@ -202,11 +202,3 @@ const DragAndDropListBox = <T extends any>(
202202
};
203203

204204
// #endregion Component
205-
206-
// -------------------------------------------------------------------------------------------------
207-
// #region Exports
208-
// -------------------------------------------------------------------------------------------------
209-
210-
export default DragAndDropListBox;
211-
212-
// #endregion Exports

src/molecules/lists/list-box.stories.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { boolean, object, text } from "@storybook/addon-knobs";
22
import React from "react";
33
import { ToastContainer, ToastPosition, Zoom } from "react-toastify";
4-
import ListBox, { ListBoxItem } from "./list-box";
4+
import { ListBox, ListBoxItem } from "./list-box";
5+
import { ToastManager } from "../../utilities/toast-manager";
56

67
export default {
78
title: "Molecules | Lists / ListBox",
@@ -33,15 +34,15 @@ export const listBoxDefault = () => {
3334
const actionText = text("Action Button Text", "Click Me!");
3435

3536
const handleActionClick = (id: number) =>
36-
window.alert(`Clicked item ${id}!`);
37+
ToastManager.success(`Clicked item ${id}!`);
3738

3839
return (
3940
<React.Fragment>
4041
<ListBox
41-
items={itemsKnob}
42+
actionText={actionText}
4243
hideWhenNoItems={hideWhenNoItems}
44+
items={itemsKnob}
4345
onActionClick={hasAction ? handleActionClick : undefined}
44-
actionText={actionText}
4546
/>
4647
<ToastContainer
4748
draggable={false}

src/molecules/lists/list-box.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ReactElement } from "react";
2-
import { CollectionUtils } from "andculturecode-javascript-core";
2+
import { CollectionUtils, StringUtils } from "andculturecode-javascript-core";
33
import { Button } from "../../atoms/buttons/button";
44
import { ButtonTypes } from "../../atoms/constants/button-types";
55
import { ButtonSizes } from "../../atoms/constants/button-sizes";
@@ -19,14 +19,14 @@ export const ListBoxItemClassName = `${ListBoxBaseClassName}__item`;
1919
// #region Interfaces
2020
// -------------------------------------------------------------------------------------------------
2121

22-
export interface ListBoxItem<T extends any> {
22+
export interface ListBoxItem<T extends string | number = string> {
2323
customAction?: React.ReactNode | React.ReactNodeArray;
2424
id: T;
2525
label?: string;
2626
text: string | React.ReactNode | React.ReactNodeArray;
2727
}
2828

29-
export interface ListBoxProps<T extends any> {
29+
export interface ListBoxProps<T extends string | number = string> {
3030
actionText?: string;
3131
children?: React.ReactNode | React.ReactNodeArray;
3232
hideWhenNoItems?: boolean;
@@ -40,7 +40,7 @@ export interface ListBoxProps<T extends any> {
4040
// #region Component
4141
// -------------------------------------------------------------------------------------------------
4242

43-
const ListBox = <T extends any>(
43+
export const ListBox = <T extends string | number = string>(
4444
props: ListBoxProps<T>
4545
): ReactElement<ListBoxProps<T>> | null => {
4646
if (props.items != null && CollectionUtils.isEmpty(props.items)) {
@@ -61,7 +61,7 @@ const ListBox = <T extends any>(
6161
props.items!.map((item: ListBoxItem<T>) => (
6262
<div className={ListBoxItemClassName} key={`${item.id}`}>
6363
{// if
64-
item.label != null && (
64+
StringUtils.hasValue(item.label) && (
6565
<div className={`${ListBoxItemClassName}__label`}>
6666
{item.label}
6767
</div>
@@ -72,11 +72,11 @@ const ListBox = <T extends any>(
7272
{// if
7373
props.onActionClick != null && (
7474
<Button
75-
type={ButtonTypes.Button}
7675
cssClassName={`${ListBoxItemClassName}__action`}
7776
onClick={() => props.onActionClick!(item.id)}
7877
size={ButtonSizes.Small}
79-
style={ButtonStyles.TertiaryAlt}>
78+
style={ButtonStyles.TertiaryAlt}
79+
type={ButtonTypes.Button}>
8080
{props.actionText ?? "Action"}
8181
</Button>
8282
)}
@@ -89,11 +89,3 @@ const ListBox = <T extends any>(
8989
};
9090

9191
// #endregion Component
92-
93-
// -------------------------------------------------------------------------------------------------
94-
// #region Exports
95-
// -------------------------------------------------------------------------------------------------
96-
97-
export default ListBox;
98-
99-
// #endregion Exports

0 commit comments

Comments
 (0)