-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a ToggleableCaret icon (#1284)
## Summary: I was starting to build this exact toggleable icon again so I've extracted the first usage into the `ToggleableCaret` component. A follow-up PR will use it in a new location. https://github.com/Khan/perseus/assets/77138/7895463c-e86d-4cb5-ac0f-76f95edfb59b Issue: "none" ## Test plan: `yarn start` Navigate to the `ToggleableCaret` story Watch for a few hours and be amazed! ✨ Author: jeremywiebe Reviewers: mark-fitzgerald, nishasy Required Reviewers: Approved By: mark-fitzgerald Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage, ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1284
- Loading branch information
1 parent
5b52a15
commit 8534a9f
Showing
5 changed files
with
71 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus-editor": minor | ||
--- | ||
|
||
Add ToggleableCaret component and use in TexErrorView |
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
31 changes: 31 additions & 0 deletions
31
packages/perseus-editor/src/components/__stories__/toggleable-caret.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,31 @@ | ||
import {SchedulePolicy, useInterval} from "@khanacademy/wonder-blocks-timing"; | ||
import * as React from "react"; | ||
|
||
import ToggleableCaret from "../toggleable-caret"; | ||
|
||
import type {StoryObj, Meta} from "@storybook/react"; | ||
|
||
type Story = StoryObj<typeof ToggleableCaret>; | ||
|
||
export default { | ||
title: "PerseusEditor/Components/Toggleable Caret", | ||
component: ToggleableCaret, | ||
} satisfies Meta; | ||
|
||
export function Transitions() { | ||
const [expanded, setExpanded] = React.useState(false); | ||
const toggler = React.useCallback(() => { | ||
setExpanded(!expanded); | ||
}, [setExpanded, expanded]); | ||
useInterval(toggler, 500, {schedulePolicy: SchedulePolicy.Immediately}); | ||
|
||
return <ToggleableCaret isExpanded={expanded} />; | ||
} | ||
|
||
export const Expanded: Story = { | ||
args: {isExpanded: true}, | ||
}; | ||
|
||
export const Collapsed: Story = { | ||
args: {isExpanded: false}, | ||
}; |
30 changes: 30 additions & 0 deletions
30
packages/perseus-editor/src/components/toggleable-caret.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,30 @@ | ||
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon"; | ||
import caretRight from "@phosphor-icons/core/bold/caret-right-bold.svg"; | ||
import {StyleSheet} from "aphrodite"; | ||
import * as React from "react"; | ||
|
||
type Props = { | ||
isExpanded: boolean; | ||
}; | ||
|
||
/** | ||
* Displays a caret in either expanded or collapsed state. For use in headings | ||
* that collapse a region. | ||
*/ | ||
function ToggleableCaret(props: Props) { | ||
const iconStyle = props.isExpanded ? styles.expanded : styles.collapsed; | ||
|
||
return <PhosphorIcon icon={caretRight} style={iconStyle} />; | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
collapsed: { | ||
transition: ".15s", | ||
}, | ||
expanded: { | ||
transform: "rotate(90deg)", | ||
transition: ".15s", | ||
}, | ||
}); | ||
|
||
export default ToggleableCaret; |
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