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


##########
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) => {

Review Comment:
   just use `React.FC` type, no need `Props`



##########
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`
+`;

Review Comment:
   ```suggestion
   const AffixContent = styled.div``;
   ```



##########
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);
+
+  const defaultHeight = parseInt(`${style.top}`, 10);

Review Comment:
   `${style.top}` really?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to