-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1619 from quadratichq/ayush/1388
feat: maintain border state
- Loading branch information
Showing
8 changed files
with
195 additions
and
160 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,36 @@ | ||
import { events } from '@/app/events/events'; | ||
import { convertTintToString } from '@/app/helpers/convertColor'; | ||
import { BorderSelection, CellBorderLine } from '@/app/quadratic-core-types'; | ||
import { colors } from '@/app/theme/colors'; | ||
import { atom, DefaultValue } from 'recoil'; | ||
|
||
interface BorderMenuState { | ||
selection?: BorderSelection; | ||
color: string; | ||
line: CellBorderLine; | ||
} | ||
|
||
const defaultBorderMenuState: BorderMenuState = { | ||
selection: undefined, | ||
color: convertTintToString(colors.defaultBorderColor), | ||
line: 'line1', | ||
}; | ||
|
||
export const borderMenuAtom = atom({ | ||
key: 'borderMenuState', | ||
default: defaultBorderMenuState, | ||
effects: [ | ||
({ setSelf }) => { | ||
const clearSelection = () => { | ||
setSelf((prev) => { | ||
if (prev instanceof DefaultValue) return defaultBorderMenuState; | ||
return { ...prev, selection: undefined }; | ||
}); | ||
}; | ||
events.on('cursorPosition', clearSelection); | ||
return () => { | ||
events.off('cursorPosition', clearSelection); | ||
}; | ||
}, | ||
], | ||
}); |
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
Oops, something went wrong.