-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2583bc3
commit df04754
Showing
6 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
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
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
8 changes: 8 additions & 0 deletions
8
src/core/primitives/Toggle/contexts/TogglePrimitiveContext.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,8 @@ | ||
import { createContext } from "react"; | ||
|
||
interface TogglePrimitiveContextType { | ||
isPressed: boolean | undefined; | ||
handlePressed: () => void; | ||
|
||
} | ||
export const TogglePrimitiveContext = createContext<TogglePrimitiveContextType>({} as TogglePrimitiveContextType) |
24 changes: 24 additions & 0 deletions
24
src/core/primitives/Toggle/fragments/TogglePrimitiveRoot.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,24 @@ | ||
import React, { useState } from "react"; | ||
|
||
export interface TogglePrimitiveRootProps { | ||
defaultPressed? : boolean | false; | ||
pressed: boolean; | ||
children?: React.ReactNode; | ||
className?: string; | ||
onChange : (isPressed:boolean) => void; | ||
|
||
} | ||
const TogglePrimitiveRoot = ({children,className='',defaultPressed,pressed,onChange,...props}:TogglePrimitiveRootProps) => { | ||
const [isPressed, setIsPressed] = useState(pressed || defaultPressed); | ||
|
||
const handlePressed = () => { | ||
const updatedPressed = !isPressed; | ||
setIsPressed(updatedPressed); | ||
onChange(updatedPressed) | ||
} | ||
|
||
return <span className={className} onClick={handlePressed} {...props}>{children}</span> | ||
|
||
}; | ||
|
||
export default TogglePrimitiveRoot; |
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,7 @@ | ||
import TogglePrimitiveRoot from "./fragments/TogglePrimitiveRoot" | ||
|
||
const TogglePrimitive = { | ||
Root: TogglePrimitiveRoot, | ||
} | ||
|
||
export default TogglePrimitive |
19 changes: 19 additions & 0 deletions
19
src/core/primitives/Toggle/stories/TogglePrimitive.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,19 @@ | ||
import React from "react"; | ||
import TogglePrimitive from "../index"; | ||
import SandboxEditor from "~/components/tools/SandboxEditor/SandboxEditor"; | ||
|
||
export default { | ||
title: 'Primitives/TogglePrimitive', | ||
component: TogglePrimitive, | ||
render: (args:any) => <SandboxEditor> | ||
|
||
<TogglePrimitive.Root {...args}> | ||
</TogglePrimitive.Root> | ||
</SandboxEditor> | ||
} | ||
|
||
export const All = { | ||
args: { | ||
className: '' | ||
} | ||
} |