barchielAbyss commented on code in PR #1115:
URL: https://github.com/apache/apisix-website/pull/1115#discussion_r878866210
##########
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:
@SkyeYoung
I don't konw there is how to run, Do I need to set `getPositionStyle ` 2
`useEffect`?
--
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]