Skip to content

Commit

Permalink
refactor(accordion): ♻️ remove console logs & rename item to trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Oct 14, 2020
1 parent a794ac6 commit e6a998b
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createHook, createComponent } from "reakit-system";
import { ACCORDION_ITEM_KEYS } from "./__keys";
import { AccordionStateReturn } from "./AccordionState";

export type AccordionItemOptions = ButtonOptions &
export type AccordionTriggerOptions = ButtonOptions &
CompositeItemOptions &
Pick<Partial<AccordionStateReturn>, "manual"> &
Pick<
Expand All @@ -28,13 +28,15 @@ export type AccordionItemOptions = ButtonOptions &
| "allowToggle"
>;

export type AccordionItemHTMLProps = ButtonHTMLProps & CompositeItemHTMLProps;
export type AccordionTriggerHTMLProps = ButtonHTMLProps &
CompositeItemHTMLProps;

export type AccordionItemProps = AccordionItemOptions & AccordionItemHTMLProps;
export type AccordionTriggerProps = AccordionTriggerOptions &
AccordionTriggerHTMLProps;

export const useAccordionItem = createHook<
AccordionItemOptions,
AccordionItemHTMLProps
export const useAccordionTrigger = createHook<
AccordionTriggerOptions,
AccordionTriggerHTMLProps
>({
name: "Accordion",
compose: [useButton, useCompositeItem],
Expand Down Expand Up @@ -125,20 +127,20 @@ export const useAccordionItem = createHook<
},
});

export const AccordionItem = createComponent({
export const AccordionTrigger = createComponent({
as: "button",
memo: true,
useHook: useAccordionItem,
useHook: useAccordionTrigger,
});

function isAccordionSelected(options: AccordionItemOptions) {
function isAccordionSelected(options: AccordionTriggerOptions) {
const { id, allowMultiple, selectedId, selectedIds } = options;

if (!allowMultiple) return selectedId === id;
return selectedIds?.includes(id);
}

function useAccordionPanelId(options: AccordionItemOptions) {
function useAccordionPanelId(options: AccordionTriggerOptions) {
const { panels, id } = options;

return React.useMemo(
Expand Down
10 changes: 5 additions & 5 deletions src/accordion/__tests__/Accordion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { axe, render, press } from "reakit-test-utils";
import {
AccordionPanel,
Accordion,
AccordionItem,
AccordionTrigger,
useAccordionState,
} from "../index";

Expand All @@ -14,17 +14,17 @@ const AccordionComponent = (props: any) => {
return (
<Accordion {...state}>
<h3>
<AccordionItem {...state}>Trigger 1</AccordionItem>
<AccordionTrigger {...state}>Trigger 1</AccordionTrigger>
</h3>
<AccordionPanel {...state}>Panel 1</AccordionPanel>
<h3>
<AccordionItem id="accordion-2" {...state}>
<AccordionTrigger id="accordion-2" {...state}>
Trigger 2
</AccordionItem>
</AccordionTrigger>
</h3>
<AccordionPanel {...state}>Panel 2</AccordionPanel>
<h3>
<AccordionItem {...state}>Trigger 3</AccordionItem>
<AccordionTrigger {...state}>Trigger 3</AccordionTrigger>
</h3>
<AccordionPanel {...state}>Panel 3</AccordionPanel>
</Accordion>
Expand Down
2 changes: 1 addition & 1 deletion src/accordion/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./AccordionState";
export * from "./Accordion";
export * from "./AccordionItem";
export * from "./AccordionTrigger";
export * from "./AccordionPanel";
26 changes: 13 additions & 13 deletions src/accordion/stories/Accordion.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "./index.css";
import {
useAccordionState,
Accordion,
AccordionItem,
AccordionTrigger,
AccordionPanel,
AccordionInitialState,
} from "../index";
Expand All @@ -20,25 +20,25 @@ const AccordionComponent: React.FC<AccordionInitialState> = props => {
return (
<Accordion {...state}>
<h2>
<AccordionItem {...state}>Trigger 1</AccordionItem>
<AccordionTrigger {...state}>Trigger 1</AccordionTrigger>
</h2>
<AccordionPanel {...state}>Panel 1</AccordionPanel>
<h2>
<AccordionItem {...state}>Trigger 2</AccordionItem>
<AccordionTrigger {...state}>Trigger 2</AccordionTrigger>
</h2>
<AccordionPanel {...state}>Panel 2</AccordionPanel>
<h2>
<AccordionItem {...state} id="accordion3">
<AccordionTrigger {...state} id="accordion3">
Trigger 3
</AccordionItem>
</AccordionTrigger>
</h2>
<AccordionPanel {...state}>Panel 3</AccordionPanel>
<h2>
<AccordionItem {...state}>Trigger 4</AccordionItem>
<AccordionTrigger {...state}>Trigger 4</AccordionTrigger>
</h2>
<AccordionPanel {...state}>Panel 4</AccordionPanel>
<h2>
<AccordionItem {...state}>Trigger 5</AccordionItem>
<AccordionTrigger {...state}>Trigger 5</AccordionTrigger>
</h2>
<AccordionPanel {...state}>Panel 5</AccordionPanel>
</Accordion>
Expand Down Expand Up @@ -66,12 +66,12 @@ export const Styled = () => {
return (
<Accordion {...props} id="accordionGroup" className="accordion">
<h2>
<AccordionItem {...props} className="accordion-trigger">
<AccordionTrigger {...props} className="accordion-trigger">
<span className="accordion-title">
Personal Information
<span className="accordion-icon"></span>
</span>
</AccordionItem>
</AccordionTrigger>
</h2>
<AccordionPanel {...props} className="accordion-panel">
<div>
Expand Down Expand Up @@ -117,12 +117,12 @@ export const Styled = () => {
</AccordionPanel>

<h2>
<AccordionItem {...props} className="accordion-trigger">
<AccordionTrigger {...props} className="accordion-trigger">
<span className="accordion-title">
Billing Address
<span className="accordion-icon"></span>
</span>
</AccordionItem>
</AccordionTrigger>
</h2>
<AccordionPanel {...props} className="accordion-panel">
<div>
Expand Down Expand Up @@ -152,12 +152,12 @@ export const Styled = () => {
</AccordionPanel>

<h2>
<AccordionItem {...props} className="accordion-trigger">
<AccordionTrigger {...props} className="accordion-trigger">
<span className="accordion-title">
Shipping Address
<span className="accordion-icon"></span>
</span>
</AccordionItem>
</AccordionTrigger>
</h2>
<AccordionPanel {...props} className="accordion-panel">
<div>
Expand Down
1 change: 0 additions & 1 deletion src/calendar/CalendarState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export function useCalendarState(props: CalendarInitialState = {}) {
onChange,
shouldUpdate: (prev, next) => prev !== next,
});
console.log("%c value", "color: #d90000", value);

const minValue = parseDate(minValueProp);
const maxValue = parseDate(maxValueProp);
Expand Down
6 changes: 1 addition & 5 deletions src/calendar/__tests__/RangeCalendar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ const RangeCalendarComp: React.FC<RangeCalendarInitialState> = props => {
const state = useRangeCalendarState(props);

return (
<Calendar
{...state}
onChange={() => console.log("change")}
className="calendar-range"
>
<Calendar {...state} className="calendar-range">
<div className="header">
<CalendarButton {...state} goto="previousYear">
previous year
Expand Down
6 changes: 1 addition & 5 deletions src/calendar/stories/RangeCalendar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ const RangeCalendarComp: React.FC<RangeCalendarInitialState> = props => {
const state = useRangeCalendarState(props);

return (
<Calendar
{...state}
onChange={() => console.log("change")}
className="calendar-range"
>
<Calendar {...state} className="calendar-range">
<div className="header">
<CalendarButton {...state} goto="previousYear" className="prev-year">
<DoubleChevronLeft />
Expand Down
6 changes: 1 addition & 5 deletions src/datepicker/stories/DateRangePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ export default {

const RangeCalendarComp: React.FC<RangeCalendarStateReturn> = state => {
return (
<Calendar
{...state}
onChange={() => console.log("change")}
className="calendar-range"
>
<Calendar {...state} className="calendar-range">
<div className="header">
<CalendarButton {...state} goto="previousYear" className="prev-year">
<DoubleChevronLeft />
Expand Down
1 change: 0 additions & 1 deletion src/number-input/stories/NumberInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { UseNumberInputProps, useNumberInputState } from "../NumberInputState";

const NumberInputComp = (props: UseNumberInputProps) => {
const state = useNumberInputState(props);
console.log("%c state", "color: #5200cc", state);

return (
<div>
Expand Down
1 change: 0 additions & 1 deletion src/select/SelectState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export const useSelectState = (
const setSelected = React.useCallback(
(value: string, shouldRemainOpen?: boolean) => {
if (allowMultiselect) {
console.log("%c selectedValue", "color: #00a3cc", selectedValue);
selectedValue.includes(value)
? setSelectedValue(selectedValue.filter(item => item !== value))
: setSelectedValue([...selectedValue, value]);
Expand Down

0 comments on commit e6a998b

Please sign in to comment.