You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/05/22 14:03:18 UTC

[GitHub] [apisix-website] SkyeYoung commented on a diff in pull request #1115: fix: Plugin route Sidebar styled error

SkyeYoung commented on code in PR #1115:
URL: https://github.com/apache/apisix-website/pull/1115#discussion_r878868566


##########
website/src/components/UI/Affix.tsx:
##########
@@ -0,0 +1,99 @@
+import type { CSSProperties, ReactNode, FC } from 'react';
+import React, { useState, useEffect } from 'react';
+import styled from 'styled-components';
+
+import { getDomStyle } from '../../utils';
+
+interface Props {
+  style: CSSProperties;
+  children: ReactNode;
+}
+
+const AffixContent = styled.div`
+`;
+
+const getPositionStyle = (
+  hasCssSticky: boolean,
+  defaultStyles: CSSProperties = {},
+):CSSProperties => {
+  const { width } = defaultStyles;
+  const positionStyle: CSSProperties = hasCssSticky ? {
+    position: 'sticky',
+    marginLeft: `-${width}px`,
+    display: 'inline-block',
+    float: 'left',
+  } : {
+    position: 'absolute',
+  };
+
+  return {
+    ...positionStyle,
+    ...defaultStyles,
+  };
+};
+
+const Affix: FC<Props> = (props) => {
+  const { style, children } = props;
+  const [hasCssSticky, SetHasCssSticky] = useState(true);
+  useEffect(() => {
+    SetHasCssSticky(CSS.supports('position', 'sticky'));
+  });
+
+  const positionStyle = getPositionStyle(hasCssSticky, style);

Review Comment:
   > I don't konw there is how to run, Do I need to set `getPositionStyle` 2 `useEffect`?
   
   You can try 🤔



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org