-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(PUPIL-442): add InternalDroppableHoldingPen
this is used in `OakQuizMatch` to hold the items that are to be matched
- Loading branch information
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...nents/organisms/pupil/InternalDroppableHoldingPen/InternalDroppableHoldingPen.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from "react"; | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { InternalDroppableHoldingPen } from "./InternalDroppableHoldingPen"; | ||
|
||
import { OakDraggable } from "@/components/molecules"; | ||
|
||
const meta: Meta<typeof InternalDroppableHoldingPen> = { | ||
component: InternalDroppableHoldingPen, | ||
tags: ["autodocs"], | ||
title: "components/organisms/pupil/InternalDroppableHoldingPen", | ||
parameters: { | ||
controls: { | ||
include: [], | ||
}, | ||
backgrounds: { | ||
default: "light", | ||
}, | ||
}, | ||
render: (args) => <InternalDroppableHoldingPen {...args} />, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof InternalDroppableHoldingPen>; | ||
|
||
export const Default: Story = {}; | ||
|
||
/** | ||
* A draggable has entered the droppable so it has entered an active state | ||
*/ | ||
export const DraggingOver: Story = { | ||
args: { | ||
isOver: true, | ||
}, | ||
}; | ||
|
||
export const Occupied: Story = { | ||
args: { | ||
children: ( | ||
<> | ||
<OakDraggable>Elephant</OakDraggable> | ||
<OakDraggable>Kangaroo</OakDraggable> | ||
<OakDraggable>Shark</OakDraggable> | ||
</> | ||
), | ||
}, | ||
}; |
19 changes: 19 additions & 0 deletions
19
...mponents/organisms/pupil/InternalDroppableHoldingPen/InternalDroppableHoldingPen.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ThemeProvider } from "styled-components"; | ||
import { create } from "react-test-renderer"; | ||
import React from "react"; | ||
|
||
import { InternalDroppableHoldingPen } from "./InternalDroppableHoldingPen"; | ||
|
||
import { oakDefaultTheme } from "@/styles"; | ||
|
||
describe("InternalDroppableHoldingPen", () => { | ||
it("matches snapshot", () => { | ||
const tree = create( | ||
<ThemeProvider theme={oakDefaultTheme}> | ||
<InternalDroppableHoldingPen /> | ||
</ThemeProvider>, | ||
).toJSON(); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
src/components/organisms/pupil/InternalDroppableHoldingPen/InternalDroppableHoldingPen.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { | ||
ComponentPropsWithRef, | ||
ComponentPropsWithoutRef, | ||
FC, | ||
forwardRef, | ||
} from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { OakFlex } from "@/components/atoms"; | ||
import { parseColor } from "@/styles/helpers/parseColor"; | ||
|
||
const StyledOakFlex = styled(OakFlex)` | ||
background-color: ${parseColor("grey20")}; | ||
background-color: color-mix(in lch, ${parseColor("black")} 5%, transparent); | ||
&[data-over="true"] { | ||
background-color: ${parseColor("white")}; | ||
background-color: color-mix( | ||
in lch, | ||
${parseColor("white")} 60%, | ||
transparent | ||
); | ||
} | ||
`; | ||
|
||
type InternalDroppableHoldingPenProps = { | ||
/** | ||
* Indicates whether a draggable is currently being dragged over the droppable | ||
*/ | ||
isOver?: boolean; | ||
}; | ||
|
||
/** | ||
* An internal holding pen for multiple draggable items | ||
* | ||
* Has no intrinsic drop functionally. | ||
* It is intended to be used with `useDroppable` from `@dnd-kit/core` | ||
*/ | ||
export const InternalDroppableHoldingPen: FC< | ||
ComponentPropsWithRef<typeof OakFlex> | ||
> = forwardRef< | ||
HTMLDivElement, | ||
InternalDroppableHoldingPenProps & ComponentPropsWithoutRef<typeof OakFlex> | ||
>(({ isOver, ...props }, ref) => { | ||
return ( | ||
<StyledOakFlex | ||
ref={ref} | ||
$pa="inner-padding-s" | ||
$mb="space-between-m2" | ||
$gap="space-between-xs" | ||
$borderRadius="border-radius-l" | ||
$flexWrap="wrap" | ||
$minHeight="all-spacing-13" | ||
data-over={isOver} | ||
{...props} | ||
/> | ||
); | ||
}); |
36 changes: 36 additions & 0 deletions
36
...pupil/InternalDroppableHoldingPen/__snapshots__/InternalDroppableHoldingPen.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`InternalDroppableHoldingPen matches snapshot 1`] = ` | ||
.c0 { | ||
min-height: 5rem; | ||
padding: 0.75rem; | ||
margin-bottom: 2rem; | ||
border-radius: 1rem; | ||
font-family: Lexend,sans-serif; | ||
} | ||
.c1 { | ||
display: -webkit-box; | ||
display: -webkit-flex; | ||
display: -ms-flexbox; | ||
display: flex; | ||
-webkit-flex-wrap: wrap; | ||
-ms-flex-wrap: wrap; | ||
flex-wrap: wrap; | ||
gap: 0.75rem; | ||
} | ||
.c2 { | ||
background-color: #f2f2f2; | ||
background-color: color-mix(in lch,#222222 5%,transparent); | ||
} | ||
.c2[data-over="true"] { | ||
background-color: #ffffff; | ||
background-color: color-mix( in lch, #ffffff 60%, transparent ); | ||
} | ||
<div | ||
className="c0 c1 c2" | ||
/> | ||
`; |
1 change: 1 addition & 0 deletions
1
src/components/organisms/pupil/InternalDroppableHoldingPen/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./InternalDroppableHoldingPen"; |