To use the EmpyreanUi
u need to install
npm install @empyreanui/core
The CodeEditor
component provides a code editor interface with support for multiple files, folder structure, and themes. It leverages the Monaco Editor for a rich coding experience and can be easily integrated into your React applications.
- Supports multiple files with a folder structure view.
- Customizable themes (default is
vs-dark
). - Customizable editor options.
- Callback functions for various editor events.
- Responsive design with customizable dimensions.
Here is an example of how to use the CodeEditor
component in a React application:
import React from "react";
import { CodeEditor } from "@empyreanui/core";
const data = {
"src/index.js":
"import React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport './index.css';\nimport App from './App';\n\nconst root = ReactDOM.createRoot(document.getElementById('root'));\nroot.render(\n <React.StrictMode>\n <App />\n </React.StrictMode>\n);",
"src/index.css": `body { margin: 0; font-family: Arial, sans-serif; }`,
};
const MyApp = () => (
<CodeEditor
data={data}
options={{ readOnly: false }}
theme="vs-dark"
width="100%"
height="600px"
onChange={(newValue) => console.log("Content changed:", newValue)}
/>
);
export default MyApp;
The CodeEditor
component accepts the following props:
Prop | Type | Description |
---|---|---|
data |
Object | string
|
The file data, either as a string for a single file or an object for multiple files. |
options |
Object |
Options for the Monaco Editor. |
defaultValue |
string |
Default value for the editor. |
defaultLanguage |
string |
Default language for the editor. |
defaultPath |
string |
Default path for the editor. |
path |
string |
Current path for the editor. |
theme |
string |
Theme for the editor. Default is vs-dark . |
line |
number |
Line number to focus on. |
loading |
string |
Loading message or component. |
overrideServices |
Object |
Override services for the editor. |
saveViewState |
boolean |
Whether to save the view state of the editor. |
keepCurrentModel |
boolean |
Whether to keep the current model in the editor. |
width |
string |
Width of the editor. |
height |
string |
Height of the editor. |
className |
string |
Additional class name for the editor. |
wrapperProps |
Object |
Additional props for the wrapper element. |
beforeMount |
Function |
Function to execute before the editor mounts. |
onMount |
Function |
Function to execute when the editor mounts. |
onChange |
Function |
Function to execute when the editor content changes. |
onValidate |
Function |
Function to execute when the editor content is validated. |
import React from "react";
import { CodeEditor } from "@empyreanui/core";
const data = {
"src/index.js":
"import React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport './index.css';\nimport App from './App';\n\nconst root = ReactDOM.createRoot(document.getElementById('root'));\nroot.render(\n <React.StrictMode>\n <App />\n </React.StrictMode>\n);",
"src/index.css": `body { margin: 0; font-family: Arial, sans-serif; }`,
};
const MyApp = () => (
<CodeEditor
data={data}
options={{ readOnly: false }}
theme="vs-dark"
width="100%"
height="600px"
onChange={(newValue) => console.log("Content changed:", newValue)}
/>
);
export default MyApp;
A component that acts as an error boundary to catch JavaScript errors in its child component tree, log those errors, and provide a fallback UI.
-
children:
ReactNode
- The children components that will be wrapped by the error boundary. -
fallbackText:
string
(optional) - The text to display in the fallback UI. -
className:
string
(optional) - Optional className for the wrapper div. -
style:
CSSProperties
(optional) - Optional inline styles for the wrapper div. -
fallbackComponent:
ReactNode
(optional) - Optional custom fallback component to render when an error is caught. -
onError:
(error: Error) => void
(optional) - Optional callback function to handle the error.
-
hasError:
boolean
- Indicates whether an error has been caught or not. -
error:
Error | null
- The error that was caught, if any.
import { ErrorBoundary } from "@empyreanui/core";
const App = () => {
return (
<ErrorBoundary fallbackText="Something went wrong!">
<YourComponent />
</ErrorBoundary>
);
};
export default App;
Constructs the ErrorBoundary component.
A lifecycle method invoked after an error is thrown in a child component. It updates the state to trigger a fallback UI.
A lifecycle method invoked after an error has been captured. It can be used for additional error logging or reporting services.
Function to reset the error state.
Renders the children components if there's no error, otherwise displays fallback UI.
A React component that applies a CSS animation class to its children when they scroll into view. This component uses the Intersection Observer API to detect when it is visible on the screen and triggers the animation.
Here's how you can use ScrollAnimationWrapper
in your project:
import React from "react";
import { ScrollAnimationWrapper } from "@empyreanui/core";
const App = () => (
<ScrollAnimationWrapper animationClass="fadeInUp" element="section">
<div className="content">This will fade in up when scrolled into view.</div>
</ScrollAnimationWrapper>
);
export default App;
ScrollAnimationWrapper
accepts the following props:
-
children
(ReactNode): The elements to be rendered inside the wrapper. -
animationClass
(string): CSS class that defines the animation to apply when the element comes into view. This class should be defined in your CSS with keyframe animations. Options include:- "fadeIn"
- "fadeInUp"
- "fadeInDown"
- "fadeInLeft"
- "fadeInRight"
- "scaleUp"
- "slideUp"
- "slideDown"
- "slideLeft"
- "slideRight"
- "rotateIn"
- Any other custom animation class
-
element
(ElementType): The HTML element type to render as the component root node. Defaults to "div". -
className
(string): Additional class names to be applied to the element.
<ScrollAnimationWrapper animationClass="fadeInUp" element="section">
<div className="content">This will fade in up when scrolled into view.</div>
</ScrollAnimationWrapper>
usePersistentState
is a custom React hook that manages state and persists it to localStorage
. This hook can be particularly useful for maintaining state across page reloads.
You can add this hook to your project by copying the code below and pasting it into your project files.
import { usePersistentState } from "@empyreanui/core";
import React from "react";
import { usePersistentState } from "@empyreanui/core";
function Counter() {
const [count, setCount] = usePersistentState("count", 0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}
export default Counter;
import React from "react";
import { usePersistentState } from "@empyreanui/core";
function UserProfile() {
const [user, setUser] = usePersistentState("user", { name: "John Doe" });
return (
<div>
<p>Name: {user.name}</p>
<button onClick={() => setUser({ name: "Jane Doe" })}>Change Name</button>
</div>
);
}
export default UserProfile;
function usePersistentState<T>(
key: string,
initialValue: T
): [T, Dispatch<SetStateAction<T>>];
-
key
(string
): The key under which the state is stored inlocalStorage
. -
initialValue
(T
): The initial value of the state.
-
[T, Dispatch<SetStateAction<T>>]
: Returns the current state and a function to update it.
const [count, setCount] = usePersistentState("count", 0);
const [user, setUser] = usePersistentState("user", { name: "John Doe" });
A custom React hook that tracks the scroll position of an HTMLElement and checks if it has scrolled beyond a specified limit.
To use this hook, simply import it into your project:
npm install your-library-name
Here is an example of how to use the useScrolled
hook in a functional React component:
import React, { useRef } from 'react';
import { useScrolled } from '@empyreanui/core';
const ScrollComponent: React.FC = () => {
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollPosition, isScrolled } = useScrolled(scrollRef, 100);
return (
<div ref={scrollRef} style={{ height: '200px', overflow: 'auto' }}>
<div style={{ height: '500px' }}>
Scroll down to see more content and check the scroll position!
</div>
<p>Scroll Position: {scrollPosition}px</p>
{isScrolled && <p>You have scrolled more than 100 pixels!</p>}
</div>
);
}
export default ScrollComponent;
-
ref
(RefObject): A React ref object pointing to the target element to monitor for scroll events. -
limit
(number): The pixel threshold after whichisScrolled
should returntrue
.
An object containing the following properties:
-
scrollPosition
(number): The current scroll position of the element. -
isScrolled
(boolean): A boolean indicating whether the scroll position has exceeded the specified limit.
import React, { useRef } from 'react';
import { useScrolled } from '@empyreanui/core';
const ScrollComponent: React.FC = () => {
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollPosition, isScrolled } = useScrolled(scrollRef, 100);
return (
<div ref={scrollRef} style={{ height: '200px', overflow: 'auto' }}>
<div style={{ height: '500px' }}>
Scroll down to see more content and check the scroll position!
</div>
<p>Scroll Position: {scrollPosition}px</p>
{isScrolled && <p>You have scrolled more than 100 pixels!</p>}
</div>
);
}
export default ScrollComponent;
Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.