| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- import {
- type TextStyle,
- type ViewStyle,
- StyleSheet,
- Platform
- } from "react-native";
- import type {
- ICodeEditorDynamicStyleProps
- } from "./type";
- import {
- webStyle
- } from "../../utils";
- const stylesheet = StyleSheet.create({
- editorInput: {
- fontFamily: Platform.OS === "web" ? "Consolas, 'Courier New', monospace" : "monospace",
- backgroundColor: "transparent",
- textAlignVertical: "top",
- position: "absolute",
- color: "transparent",
- fontWeight: "400",
- letterSpacing: 0,
- borderWidth: 0,
- lineHeight: 24,
- fontSize: 14,
- padding: 0,
- margin: 0,
- bottom: 0,
- right: 0,
- left: 0,
- top: 0,
- ...webStyle({
- fontVariantLigatures: "none",
- caretColor: "inherit",
- outline: "none",
- resize: "none"
- })
- },
- content: {
- fontFamily: Platform.OS === "web" ? "Consolas, 'Courier New', monospace" : "monospace",
- fontWeight: "400",
- letterSpacing: 0,
- ...webStyle({
- whiteSpace: Platform.OS === "web" ? "pre" : "pre-wrap",
- fontVariantLigatures: "none"
- })
- },
- codeText: {
- fontFamily: Platform.OS === "web" ? "Consolas, 'Courier New', monospace" : "monospace",
- fontWeight: "400",
- letterSpacing: 0,
- fontSize: 14,
- ...webStyle({
- fontVariantLigatures: "none"
- })
- },
- lineNumber: {
- fontFamily: Platform.OS === "web" ? "monospace" : "System",
- textAlign: "right",
- marginRight: 4,
- lineHeight: 24,
- fontSize: 12,
- ...webStyle({
- userSelect: "none"
- })
- },
- toolbarContainer: {
- justifyContent: "flex-start",
- borderBottomWidth: 0,
- alignItems: "center",
- flexDirection: "row",
- position: "relative",
- paddingVertical: 4,
- flexWrap: "wrap",
- zIndex: 1
- },
- gutter: {
- justifyContent: "flex-end",
- alignItems: "flex-start",
- flexDirection: "row",
- borderRightWidth: 1,
- ...webStyle({
- userSelect: "none"
- })
- },
- lineRow: {
- alignItems: "flex-start",
- flexDirection: "row",
- minHeight: 24
- },
- container: {
- flexDirection: "column",
- position: "relative",
- width: "100%"
- },
- editorContainer: {
- position: "relative",
- zIndex: 0
- },
- scrollContent: {
- minWidth: "100%",
- flexGrow: 1
- },
- text: {
- lineHeight: 24
- },
- scrollView: {
- flex: 1
- }
- });
- export const useStyles = ({
- isLineNumberVisible = true,
- isToolbarVisible = false,
- hasLanguage = false,
- spreadBehaviour,
- typography,
- radiuses,
- borders,
- colors,
- spaces
- }: ICodeEditorDynamicStyleProps) => {
- let gutterPaddingRight = 6;
- let gutterMarginRight = 8;
- let gutterWidth = 32;
- if (!isLineNumberVisible) {
- gutterPaddingRight = 0;
- gutterMarginRight = 0;
- gutterWidth = 0;
- }
- const languageMarginLeft = spaces.spacingSm;
- const lineHeight = (typography.bodyMediumSize?.lineHeight as number) || 24;
- const styles = {
- container: {
- alignSelf: spreadBehaviour === "stretch" ? "stretch" : (spreadBehaviour === "baseline" ? "baseline" : "auto"),
- width: spreadBehaviour === "baseline" ? "auto" : "100%",
- marginVertical: spaces.spacingSm
- } as ViewStyle,
- editorInput: {
- ...typography.bodyMediumSize,
- paddingLeft: (isLineNumberVisible ? (gutterWidth + gutterMarginRight) : spaces.spacingSm),
- fontFamily: Platform.OS === "web" ? "Consolas, 'Courier New', monospace" : "monospace",
- paddingTop: hasLanguage ? (lineHeight + spaces.spacingSm) : 0,
- paddingRight: spaces.spacingMd,
- ...webStyle({
- caretColor: colors.content.text.high
- })
- } as TextStyle,
- text: {
- ...typography.bodyMediumSize,
- fontFamily: Platform.OS === "web" ? "Consolas, 'Courier New', monospace" : "monospace"
- } as TextStyle,
- editorContainer: {
- paddingTop: isToolbarVisible ? spaces.spacingXs : spaces.spacingMd,
- borderTopRightRadius: isToolbarVisible ? 0 : radiuses.form,
- borderTopLeftRadius: isToolbarVisible ? 0 : radiuses.form,
- backgroundColor: colors.content.container.subtle,
- borderColor: colors.content.border.subtle,
- borderBottomRightRadius: radiuses.form,
- borderBottomLeftRadius: radiuses.form,
- paddingHorizontal: spaces.spacingMd,
- paddingBottom: spaces.spacingMd,
- borderWidth: borders.line,
- borderTopWidth: isToolbarVisible ? 0 : borders.line
- } as ViewStyle,
- lineRow: {
- marginLeft: !isLineNumberVisible ? spaces.spacingSm : 0,
- minHeight: lineHeight,
- height: lineHeight
- } as ViewStyle,
- toolbarContainer: {
- backgroundColor: colors.content.container.subtle,
- borderColor: colors.content.border.subtle,
- borderTopRightRadius: radiuses.form,
- paddingHorizontal: spaces.spacingMd,
- borderTopLeftRadius: radiuses.form,
- paddingBottom: spaces.spacingXs,
- borderRightWidth: borders.line,
- borderLeftWidth: borders.line,
- borderTopWidth: borders.line,
- paddingTop: spaces.spacingMd,
- gap: spaces.spacingXs
- } as ViewStyle,
- toolbarActionBtn: {
- paddingHorizontal: spaces.spacingMd,
- paddingVertical: spaces.spacingSm
- } as ViewStyle,
- gutter: {
- paddingRight: gutterPaddingRight,
- marginRight: gutterMarginRight,
- width: gutterWidth
- } as ViewStyle,
- languageText: {
- marginBottom: spaces.spacingSm,
- color: colors.content.text.low,
- marginLeft: languageMarginLeft,
- ...webStyle({
- userSelect: "none"
- })
- } as TextStyle
- };
- return styles;
- };
- export default stylesheet;
|