border radius project

pull/511/head
Leonardo Santos 4 years ago
parent b47cf8261f
commit a8d00e3250

@ -7,12 +7,12 @@ The border-radius property can have multiple values changed. Preview how the sha
## User Stories
- [ ] User can see a box which has a `border-radius` property applied to it
- [ ] User can change the 4 `border-radius` values that are applied to the box (top-left, top-right, bottom-left, bottom-right)
- [ ] User can copy the resulting CSS to the clipboard
- [x] User can change the 4 `border-radius` values that are applied to the box (top-left, top-right, bottom-left, bottom-right)
- [x] User can copy the resulting CSS to the clipboard
## Bonus features
- [ ] User can change all 8 possible values of the border-radius in order to create a complex shape
- [x] User can change all 8 possible values of the border-radius in order to create a complex shape
## Useful links and resources

@ -0,0 +1,36 @@
{
"name": "app-ideas",
"version": "0.1.0",
"private": true,
"dependencies": {
"@reduxjs/toolkit": "^1.5.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.3",
"react-scripts": "4.0.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React Redux App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

@ -0,0 +1,2 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *

@ -0,0 +1,13 @@
import React from 'react';
import { Square } from './features';
import styles from './App.module.css';
function App() {
return (
<main className={styles.main}>
<Square />
</main>
);
}
export default App;

@ -0,0 +1,29 @@
.main {
width: 100vw;
max-width: 100%;
height: 100vh;
background: linear-gradient(253deg, #542466, #955d98);
background-size: 400% 400%;
-webkit-animation: GradientAnimation 6s ease infinite;
-moz-animation: GradientAnimation 6s ease infinite;
animation: GradientAnimation 6s ease infinite;
display: grid;
place-items: center;
padding: 1rem;
}
@-webkit-keyframes GradientAnimation {
0%{background-position:0% 50%}
50%{background-position:100% 50%}
100%{background-position:0% 50%}
}
@-moz-keyframes GradientAnimation {
0%{background-position:0% 50%}
50%{background-position:100% 50%}
100%{background-position:0% 50%}
}
@keyframes GradientAnimation {
0%{background-position:0% 50%}
50%{background-position:100% 50%}
100%{background-position:0% 50%}
}

@ -0,0 +1,15 @@
import React from 'react';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import { store } from './app/store';
import App from './App';
test('renders learn react link', () => {
const { getByText } = render(
<Provider store={store}>
<App />
</Provider>
);
expect(getByText(/learn/i)).toBeInTheDocument();
});

@ -0,0 +1,76 @@
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import {
adjust,
selectBottomLeft,
selectBottomRight,
selectTopLeft,
selectTopRight,
selectLeftTop,
selectRightTop,
selectRightBottom,
selectLeftBottom,
} from './squareSlice';
import style from './Square.module.css';
const Square = () => {
const sides = {
bottomLeft: useSelector(selectBottomLeft),
bottomRight: useSelector(selectBottomRight),
topLeft: useSelector(selectTopLeft),
topRight: useSelector(selectTopRight),
leftTop: useSelector(selectLeftTop),
rightTop: useSelector(selectRightTop),
rightBottom: useSelector(selectRightBottom),
leftBottom: useSelector(selectLeftBottom),
};
const firstValues = `${sides.topLeft}% ${sides.topRight}% ${sides.bottomLeft}% ${sides.bottomRight}%`;
const secondValues = `${sides.leftTop}% ${sides.rightTop}% ${sides.rightBottom}% ${sides.leftBottom}%`;
const dispatch = useDispatch();
const handleChange = ({ target: { name, value } }) => {
dispatch(adjust({ side: name, value: Number(value) }));
};
const renderInputs = () => {
return (
<article className={style.inputContainer}>
{Object.entries(sides).map((side) => (
<input
className={style.input}
value={side[1]}
onChange={handleChange}
type='number'
name={side[0]}
/>
))}
<button
onClick={() => navigator.clipboard.writeText(`${firstValues} / ${secondValues}`)}
>Copiar valores</button>
</article>
);
};
const renderSquare = () => {
return (
<article className={style.squareContainer}>
<div
className={style.square}
style={{
borderRadius: `${firstValues} / ${secondValues}`,
}}
></div>
</article>
);
};
return (
<section className={style.section}>
{renderInputs()}
{renderSquare()}
</section>
);
};
export default Square;

@ -0,0 +1,47 @@
.section {
width: 100%;
height: 100%;
display: grid;
place-items: center;
margin: auto;
align-content: space-evenly;
grid: 0.5fr 3fr / 1fr;
}
.inputContainer {
width: 100%;
display: grid;
height: 100%;
grid: 1fr 1fr / repeat(auto-fit, minmax(8rem, 1fr));
gap: 1rem;
place-items: center;
}
.input {
border: 0;
border-radius: 2rem;
height: 100%;
text-align: center;
display: inline-block;
max-width: 100%;
vertical-align: middle;
}
.squareContainer {
border: 2px dotted blue;
}
.square {
width: 45vw;
height: 70vh;
background: violet;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
transition: all 2s ease;
position: relative;
}
.square:hover {
background: purple;
box-shadow: 0px 15px 2px rgba(0, 0, 0, 0.5);
cursor: pointer;
}

@ -0,0 +1,3 @@
import { default as Square } from './Square';
import { default as squareReducer } from './squareSlice';
export { Square, squareReducer };

@ -0,0 +1,58 @@
import { createSlice } from '@reduxjs/toolkit';
/* SECTION Structure
NOTE Before slash
first value applies to top-left corner
second value applies to top-right corner
third value applies to bottom-right corner
fourth value applies to bottom-left corner
NOTE After slash
first value applies to left-top corner
second value applies to right-top corner
third value applies to right-bottom corner
fourth value applies to left-bottom corner
0% 0% 0% 0% / 0% 0% 0% 0%
!SECTION */
const initialState = {
bottomLeft: 0,
bottomRight: 0,
topLeft: 0,
topRight: 0,
leftTop: 0,
rightTop: 0,
rightBottom: 0,
leftBottom: 0,
};
export const squareSlice = createSlice({
name: 'square',
initialState,
reducers: {
increment: (state, action) => {
state[action.side] += 1;
},
decrement: (state, action) => {
state[action.side] -= 1;
},
adjust: (state, action) => {
state[action.payload.side] = action.payload.value;
},
},
});
export const { adjust, increment, decrement } = squareSlice.actions;
export const selectBottomLeft = ({ square }) => square.bottomLeft;
export const selectBottomRight = ({ square }) => square.bottomRight;
export const selectTopLeft = ({ square }) => square.topLeft;
export const selectTopRight = ({ square }) => square.topRight;
export const selectLeftTop = ({ square }) => square.leftTop;
export const selectRightTop = ({ square }) => square.rightTop;
export const selectRightBottom = ({ square }) => square.rightBottom;
export const selectLeftBottom = ({ square }) => square.leftBottom;
export default squareSlice.reducer;

@ -0,0 +1,5 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

@ -0,0 +1,18 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import store from './redux';
import { Provider } from 'react-redux';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
document.getElementById('root')
);
serviceWorker.unregister();

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><g fill="#764ABC"><path d="M65.6 65.4c2.9-.3 5.1-2.8 5-5.8-.1-3-2.6-5.4-5.6-5.4h-.2c-3.1.1-5.5 2.7-5.4 5.8.1 1.5.7 2.8 1.6 3.7-3.4 6.7-8.6 11.6-16.4 15.7-5.3 2.8-10.8 3.8-16.3 3.1-4.5-.6-8-2.6-10.2-5.9-3.2-4.9-3.5-10.2-.8-15.5 1.9-3.8 4.9-6.6 6.8-8-.4-1.3-1-3.5-1.3-5.1-14.5 10.5-13 24.7-8.6 31.4 3.3 5 10 8.1 17.4 8.1 2 0 4-.2 6-.7 12.8-2.5 22.5-10.1 28-21.4z"/><path d="M83.2 53c-7.6-8.9-18.8-13.8-31.6-13.8H50c-.9-1.8-2.8-3-4.9-3h-.2c-3.1.1-5.5 2.7-5.4 5.8.1 3 2.6 5.4 5.6 5.4h.2c2.2-.1 4.1-1.5 4.9-3.4H52c7.6 0 14.8 2.2 21.3 6.5 5 3.3 8.6 7.6 10.6 12.8 1.7 4.2 1.6 8.3-.2 11.8-2.8 5.3-7.5 8.2-13.7 8.2-4 0-7.8-1.2-9.8-2.1-1.1 1-3.1 2.6-4.5 3.6 4.3 2 8.7 3.1 12.9 3.1 9.6 0 16.7-5.3 19.4-10.6 2.9-5.8 2.7-15.8-4.8-24.3z"/><path d="M32.4 67.1c.1 3 2.6 5.4 5.6 5.4h.2c3.1-.1 5.5-2.7 5.4-5.8-.1-3-2.6-5.4-5.6-5.4h-.2c-.2 0-.5 0-.7.1-4.1-6.8-5.8-14.2-5.2-22.2.4-6 2.4-11.2 5.9-15.5 2.9-3.7 8.5-5.5 12.3-5.6 10.6-.2 15.1 13 15.4 18.3 1.3.3 3.5 1 5 1.5-1.2-16.2-11.2-24.6-20.8-24.6-9 0-17.3 6.5-20.6 16.1-4.6 12.8-1.6 25.1 4 34.8-.5.7-.8 1.8-.7 2.9z"/></g></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1,8 @@
import { configureStore } from '@reduxjs/toolkit';
import { squareReducer } from '../features';
export default configureStore({
reducer: {
square: squareReducer,
},
});

@ -0,0 +1,137 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then((registration) => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch((error) => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { 'Service-Worker': 'script' },
})
.then((response) => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then((registration) => {
registration.unregister();
});
}
}

@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save