Skip to content

Commit

Permalink
added reactor router dom fo navigation to different components
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjeetkumaritoutlook committed Dec 14, 2024
1 parent 17bcdaf commit 5b6967c
Show file tree
Hide file tree
Showing 10 changed files with 630 additions and 51 deletions.
61 changes: 48 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"@types/node": "^16.18.29",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"axios": "^1.7.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.24.0",
"react-router-dom": "^6.28.0",
"react-scripts": "5.0.1",
"stenciljs-components": "^1.0.3",
"typescript": "^4.9.5",
Expand Down
77 changes: 57 additions & 20 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,66 @@
import React from 'react';
//import logo from './logo.svg';
//https://stackoverflow.com/questions/69843615/switch-is-not-exported-from-react-router-dom
//https://www.w3schools.com/react/react_router.asp
import { BrowserRouter as Router, Routes,Route, Link } from "react-router-dom";
//Routes instead of Switch from v6
//elements instead of component
//CSS or CSS-in-JS (if you prefer inline styles or styled-components).
import './App.css';
//import Header from './components/Header';
//import DarkMode from "./components/DarkMode";
//import Counter from './components/Counter';
//import Timer from './components/Timer';
import './Navbar.css';
import Header from './components/Header';
import DarkMode from "./components/DarkMode";
import Counter from './components/Counter';
import Timer from './components/Timer';
import LibraryComponents from './components/LibraryComponents';
import FluidForm from './components/FluidForm';
import FluidUpload from './components/FluidUpload';
import AxiosCall from './components/AxiosCall';
function App() {
return (
<div className="App">
<h1>from 'stenciljs-components' npm package</h1>
<my-card user-name="CodingLocker"></my-card>
<my-pie-chart data='[{"tag":"height","value":180},{"tag":"weight","value":75},{"tag":"age","value":30},{"tag":"score","value":95},{"tag":"yearsExperience","value":5}]'></my-pie-chart>
<my-rich-text-editor initial-value="this is Reaact value" placeholder="React placeholder"></my-rich-text-editor>
<my-progress-bar value="2" max="10"></my-progress-bar>
<my-progress-ring percentage="30"></my-progress-ring>
<test-button button-id="test-button">Click me!</test-button>
<test-counter>Number: </test-counter>
<search-world search-text="bmw"> </search-world>
<my-payment-gateway></my-payment-gateway>
<my-component first="Sanjeet" last="Kumar"></my-component>
<simple-form></simple-form>
<custom-form></custom-form>
<complex-ionic-form></complex-ionic-form>
<combo-box allow-input='true' label='Album:'></combo-box>
</div>
<Router>
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/library-components">Library Components</Link>
</li>
<li>
<Link to="/fluid-form">Fluid Form</Link>
</li>
<li>
<Link to="/darkmode">Darkmode</Link>
</li>
<li>
<Link to="/counter">Counter</Link>
</li>
<li>
<Link to="/timer">timer</Link>
</li>
<li>
<Link to="/fluid-upload">Upload</Link>
</li>
<li>
<Link to="/axios-call">Axios Call</Link>
</li>
</ul>
</nav>

<Routes>
<Route path="/" element={<Header/>} />
<Route path="/library-components" element={<LibraryComponents/>} />
<Route path="/fluid-form" element={<FluidForm/>} />
<Route path="/darkmode" element={<DarkMode/>} />
<Route path="/counter" element={<Counter/>} />
<Route path="/timer" element={<Timer/>} />
<Route path="/fluid-upload" element={<FluidUpload/>} />
<Route path="/axios-call" element={<AxiosCall/>} />
</Routes>
</Router>
</div>
);
}

Expand Down
54 changes: 54 additions & 0 deletions src/Navbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* Nav container */
nav {
background-color: #2c3e50; /* Dark background */
padding: 10px 20px; /* Space around the nav */
border-radius: 8px; /* Rounded corners */
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1); /* Subtle shadow */
}

/* Unordered list styles */
nav ul {
list-style: none; /* Remove bullets */
display: flex; /* Align items horizontally */
justify-content: center; /* Center items horizontally */
margin: 0; /* Remove default margin */
padding: 0; /* Remove default padding */
}

/* List item styles */
nav ul li {
margin: 0 15px; /* Space between links */
}

/* Link styles */
nav ul li a {
text-decoration: none; /* Remove underline */
color: white; /* White text */
font-size: 18px; /* Larger font size */
font-weight: bold; /* Bold font */
padding: 8px 16px; /* Space around the text */
border-radius: 4px; /* Rounded corners for each link */
transition: background-color 0.3s ease, transform 0.3s ease; /* Smooth transition */
}

/* Link hover styles */
nav ul li a:hover {
background-color: #3498db; /* Blue background on hover */
transform: scale(1.1); /* Slightly enlarge on hover */
}

/* Link active styles */
nav ul li a.active {
color: #e74c3c; /* Red color when active */
border-bottom: 3px solid #e74c3c; /* Red underline when active */
}
/*
Explanation of the Styles:
-------------
1.nav: The background-color is set to a dark shade for a modern look, and box-shadow adds a subtle depth effect.
2.ul: Flexbox is used to horizontally align the items and justify-content: center centers the links.
3.li: Margin is used to space the links apart.
4.a: The links have no underline by default, and the text is white for contrast against the dark background. The border-radius adds rounded corners to the links for a soft look.
5.Hover Effect: When you hover over a link, it changes the background color and slightly enlarges to create a "pop" effect.
6.Active Link: If you want the active link to be highlighted, you can apply the .active class in React based on the current route (this will be added dynamically as the user navigates).
*/
131 changes: 131 additions & 0 deletions src/components/AxiosCall.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import React from 'react';
import { useCustomElementRef, fluid } from './../fluid'; // Replaced by @lmig/fluid-react-utils
import { useEffect,useState } from 'react';
//built-in fetch API or a library like axios
//npm i axios
import axios from 'axios';

function AxiosCall() {

// ---- Initialise FLUID
let env:any = fluid.environments.external;
useEffect(() => fluid.init(env));
//since its typescript, cannot use with empty dependency
//useEffect(() => fluid.init(env), []);
// ---- Start Building
const [response, setResponse] = useState(null);

const validation = [
{
type: 'required',
value: true,
message: 'This is a required field.',
},
];
const fluidFormRef = useCustomElementRef(
{ valueChanged: (event:any) => {
console.log('value changed');
},
formChanged: (event:any) => {
console.log(event.detail);
},
actionClicked: (event:any) => {
console.log(event.detail.data.redactedValue);
const sendData = async () => {
try {
const res = await axios.post('https://jsonplaceholder.typicode.com/posts', event.detail.data.redactedValue, {
headers: {
'Content-Type': 'application/json', // Ensures JSON content
},
});

console.log(res.data);
setResponse(res.data);
} catch (error) {
console.error('Error:', error);
}
};
sendData();
},
},
{
config: {
layout: 'vertical',
elements: [
{
dataPath: 'textInput',
label: 'My Text Input',
type: 'input',
controlName: 'textInput',
validation,
},
{
dataPath: 'array',
label: 'Array Section',
elementType: 'array',

constraints: {
minimumEntries: 2,
maximumEntries: 8,
},

initialValue: [
{ phoneNumber: '(801) 999-9999' },
{ phoneNumber: '(801) 222-2222' },
],

controlName: 'array',
formConfig: {
allowDeleteForm: (data: {
redactedValue?: { phoneNumber: number };
}) => {
const test = !data?.redactedValue?.phoneNumber;
//console.log('data::', data, test);
return test;
},

elements: [
{
dataPath: 'phoneNumber',
label: 'phone',
type: 'input',
controlName: 'phoneNumber',
},
],
},
},
],
submitConfig: {
actionText: 'Save',
actionKey: 'formSubmitted',
},
cancelConfig: {
actionText: 'Cancel',
actionKey: 'formCancelled',
displayDialogBeforeAction: true,
},
},
}
);
console.log('fluidFormRef', fluidFormRef);

// const btRef = useCustomElementRef(
// {
// click: async () => {
// console.log('click', fluidFormRef);
// const test = await fluidFormRef.current.markTouchedAndValidate();
// console.log('test');
// },
// },
// { label: 'Test useCustomElementRef.current' }
// );
return (
<div>
<fluid-text>Your Code Here</fluid-text>
<fluid-form ref={fluidFormRef}></fluid-form>
{response && <pre>Response: {JSON.stringify(response, null, 2)}</pre>}
</div>
);
}

export default AxiosCall;
Loading

0 comments on commit 5b6967c

Please sign in to comment.