#create usestyles is not a function
Explore tagged Tumblr posts
airman7com · 5 years ago
Text
Create And Uses Of Laravel Macro Example
Create And Uses Of Laravel Macro Example
Today I will discuss about laravel macro
Macro is a powerful feature of the laravel framework. Macros allow you to add special functionality to internal Laravel components. This laravel macro also works with laravel 5.8, 5.7 and 5.6.
Let’s look at Laravel Macro Example 1
Say you work with fire and want a response below about success
{ "success": true, "msg": "Your message", "data": Array() }
View On WordPress
0 notes
pollthepeople · 3 years ago
Text
5 Tips For Creating Highly Optimized Figma Designs
5 Tips For Creating Highly Optimized Figma Designs
Creating optimized Figma designs doesn’t have to be a daunting task. With these five tips, you can streamline your workflow and create designs that are both efficient and effective.
Designing In Figma: 5 Tips For Creating Highly Optimized Designs
Designing in Figma can be a great way to create highly optimized designs. Here are 5 tips to help you get the most out of your Figma design:
1. Use layers to organize your design.
2. Use the right color palette.
3. Use grids and guides to align your elements.
4. UseStyles to format your text and objects.
5. Use Preview Mode to test your design.
Figma Tips: How To Optimize Your Designs
1. Keep it simple
The simplest designs are often the most effective. When creating a design in Figma, keep this in mind and aim for simplicity.
2. Use constraints
Constraints help you to Stay within the margins and keep your design looking neat and organized. By setting constraints on your layers, you can ensure that your design elements are always properly aligned.
3. use consistent spacing
Spacing is important in design for both aesthetic and functional purposes. When creating a design in Figma, be sure to use consistent spacing throughout. This will give your design a clean and professional look.
4. use colors sparingly
With colors, less is usually more. When creating a design in Figma, use colors sparingly to create a more sophisticated look.
5. choose appropriate fonts
Fonts can make or break a design. When choosing fonts for your design, be sure to select ones that are legible and appropriate for the project.
5 Tips For Optimizing Your Figma Designs
1. Use a set of simple, reusable components
When you’re creating a design in Figma, it’s important to use a set of simple, reusable components. This will help you keep your design organized and minimize the amount of time you spend on small details.
2. Organize your layers
Figma’s layer tool is a great way to keep your design organized. You can use it to group similar objects together and make sure everything is in its proper place.
3. Use Figma’s grid system
Figma’s grid system is a great way to ensure that your design is consistent and visually appealing. By aligning objects to the grid, you can create a clean, professional look.
4. Use constraints
Figma’s constraints feature is a great way to keep your design responsive. By setting constraints, you can ensure that your objects will resize and reposition themselves properly on different screen sizes.
5. Export your assets
When you’re finished with your design, be sure to export your assets. This will allow you to use them in other projects and ensure that they’re always high-quality.
BONUS TIP:
If you want to create highly optimized Figma designs, then you need to sign up for a free Poll the People account. With Poll the People, you can test your designs with real users and get feedback that will help you improve your designs. So what are you waiting for? Sign up for a free account today and start creating better designs!
Read More At: https://pollthepeople.app/figma-designs/
0 notes
holytheoristtastemaker · 5 years ago
Link
Magnify The magnify effect increases the size of an item as the mouse approaches it, then animates its exit state as a flip should the mouse enter and then leave it. This is a useful example of stateful coroutines. I've implemented it as a React wrapper component that can perform the effect on its children.
export function MagnifyBox({ children, from = 1, to = 1.8, flipFrames = 60, radius = 15, ...props }) { const ref = useRef() const classes = useStyles() useEffect(() => { const promise = magnify(ref.current, from, to, radius, flipFrames) return promise.terminate }) return ( <Box ref={ref} className={classes.magnify} {...props}> {children} </Box> ) }
Here we create a simple Material UI Box wrapper that creates a coroutine in it's useEffect and calls the exit function of the coroutine should it unmount.
The coroutine
The magnify call creates a coroutine to perform the animation:
export function magnify( element, from = 0.9, to = 1.5, radius = 5, flipFrames = 60 ) { if (!element) return const pos = rect() const zIndex = element.style.zIndex || 0 const initialTransform = element.style.transform || "" const SCALING_FACTOR = pos.width + pos.height * 2 //Get js-coroutines to run our function in high priority return update(run) ...
The first part of the function grabs some useful stuff from the element to be animated and uses js-coroutines to start a high priority update animation. Then we have 2 animation states, the first one is about the mouse approaching the item, the second about flipping. In the main animation we resize the item based on mouse position and then check if we are moving from inside to outside, which should trigger the flip.
//Standard animation function* run() { let inside = false while (true) { //Resize based on mouse position const [, middleX] = resize() const outside = Math.abs(middleX - x) > pos.width if (!outside) { inside = true } else { if (inside) { inside = false //Use the flip animation until complete yield* flip(middleX > x ? 1 : -1) } } yield } }
resize performs cursor distance resizing:
function resize() { const pos = rect() let middleX = pos.width / 2 + pos.x let middleY = pos.height / 2 + pos.y let d = Math.sqrt((x - middleX) ** 2 + (y - middleY) ** 2) const value = lerp(to, from, clamp((d - radius) / SCALING_FACTOR)) element.style.transform = `scale(${value}) ${initialTransform}` element.style.zIndex = zIndex + ((((value - from) / (to - from)) * 1000) | 0) return [d, middleX, middleY] } function clamp(t) { return Math.max(0, Math.min(1, t)) } function lerp(a, b, t) { return (b - a) * t + a }
Then when it's time to flip, we just do a for-next loop, which is the joy of using a stateful generator function when writing imperative animations that execute over multiple frames:
function* flip(direction = 1) { for (let angle = 0; angle < 360; angle += 360 / flipFrames) { //Still perform the resize resize() //Make the item "grey" on the back if (angle > 90 && angle < 270) { element.style.filter = `grayscale(1)` } else { element.style.filter = `` } element.style.transform = `${ element.style.transform } rotate3d(0,1,0,${angle * direction}deg)` //Wait until next frame yield } }
Miscellany
Getting the mouse position is achieved by adding a global handler to the document:
let x = 0 let y = 0 function trackMousePosition() { document.addEventListener("mousemove", storeMousePosition) } trackMousePosition() function storeMousePosition(event) { x = event.pageX y = event.pageY }
And then using the effect is a case of wrapping MagnifyBox around the content:
<Box mt={10} display="flex" flexWrap="wrap" justifyContent="center"> {icons.map((Icon, index) => { return ( <MagnifyBox key={index} mr={2} to={2.5} from={1}> <IconButton style={{ color: "white", background: colors[index] }} > <Icon /> </IconButton> </MagnifyBox> ) })} </Box>
Conclusion
Hopefully this example has shown how easy it is to write stateful animations using generator functions and js-coroutines!
0 notes
holytheoristtastemaker · 5 years ago
Link
Material design was introduced by Google around 2014 as a design language and it still shares some popularity among web and mobile applications. One of the common ways to integrate and use this design system in React apps is through MaterialUI library.
Tumblr media
In this post, let us take a look at how to integrate a material library that is available as an npm module and consists of built React components that you can use to build apps. You are going to learn from scratch on how to install and configure this library as well as build a small demo app.
Tumblr media
Prerequisites
Before you begin this tutorial you are going to need the following:
a Web browser such as Chrome, Firefox and so on
Node.js version above 12.x.x installed on your local machine
JavaScript/ES6 basics
React basics
npm/yarn install
either create-react-app globally installed or access via npx
Create a new React app
To start, you are going to need to setup a React project. Let's use npx to do so. Execute the following command in a terminal window.
npx create-react-app reactmaterial
By using the npx command (a part of the Node Package Manager (npm)) you execute create-react-app without the need to download and install the package globally. When the new project is done scaffolding with the default dependencies such as React library and React DOM library installed. Change in the new directory and you are going to be welcomed by the following structure of files and folders.
Tumblr media
To verify that the React app is working, (you can totally skip the step at this time), run yarn start from the terminal window and open the default React app running at http://localhost:3000 in a browser window.
Tumblr media
Install Material UI library
The next step is to install the Material-UI library and integrate it to work with the current React app. The first is to install the core dependency of this library.
yarn add @material-ui/core
Material-UI was designed with the Roboto font in mind. If you wish to use it, you can follow the instructions. Go back to the terminal window and install the typeface package of the font. Also note that, the following steps to install this font are optional.
yarn add typeface-roboto
Then go to the entry point of your React app (preferably, ./src/index.js file) and import the font.
// rest of the import statements import 'typeface-roboto';
Alternatively, if you do not wish to install the above npm module for the font, you can also use the CDN version of the font and read about it here.
Using AppBar to create a custom navigation bar
In this section let us build a navigation bar. Create a new file called ./src/components/Navbar.js and start by importing the components AppBar, ToolBar, and Typography from the MaterialUI library. The AppBar component is used to display branding, screen titles, and navigation of the web app. That is what you are going to use it for. The ToolBar component is wrapper where you can place your components horizontally. The Typography component applies the Material UI theme that is available by default.
import React from 'react'; import { AppBar, Toolbar, Typography } from '@material-ui/core';
Next, export a function component called Navbar with the following JSX.
export default function Navbar() { return ( <AppBar> <Toolbar> <Typography variant='h6'>React and Material-UI App</Typography> </Toolbar> </AppBar> ); }
In the code snippet above, notice the variant prop on the Typography component. It uses the variant mapping to properly associate a UI element with an HTML semantic element (such as h6 in the code snippet). Now, to see it in action, import the Navbar component in the App.js file.
import React from 'react'; import Navbar from './components/Navbar'; function App() { return ( <div> <Navbar /> </div> ); } export default App;
You are going to get the following result after this step.
Tumblr media
Implementing a Paper component
Two components that are going to be used in this section in order to layout a view for the items of the list are called Grid and Paper. Material Design’s responsive UI is based on a 12-column grid layout. The Grid component helps you implement this layout system and then provide the values or the number of grids you want to display. A basic grid might look like below:
Tumblr media
Material UI uses CSS's Flexbox to manage layout alignments and sizing of the grid columns. The other component Paper actually displays the physical properties of a paper on the screen. It resembles a flat, texture of a sheet of paper, and using a prop called elevation you can manipulate its default display behavior. Do note that, this component does need an initial width and height. Create a new component file called ./src/components/List.js which is going to be used as a reusable component later. This presentational component is going to display a Paper component inside Grid with custom styles.
import React from 'react'; import { Grid, Paper, makeStyles } from '@material-ui/core'; const useStyles = makeStyles(theme => ({ root: { marginTop: 100, flexGrow: 1 }, paper: { height: 220, width: 340, backgroundColor: '#ebebeb' }, avatarImage: { width: 200, height: 200, borderRadius: 100 } })); export default function List() { const classes = useStyles(); return ( <Grid container spacing={2}> <Grid item className={classes.root} xs={12}> <Grid container justify='center' spacing={2}> <Grid key={1} item> <Paper className={classes.paper} elevation={2} /> </Grid> </Grid> </Grid> </Grid> ); }
The makeStyles comes from the Material UI API. It links a style sheet with a function component and returns a hook that you use inside the component. You can modify the App.js file to include the List component.
// rest of the import statements import List from './components/List'; function App() { return ( <div> <Navbar /> <List /> </div> ); }
Here is the result you are going to get after this step.
Tumblr media
Fetching random user data
To display data inside List component, let us use https://randomuser.me/ API. In the App component the data is going to be fetched on the initial render using useEffect hook. The useState hook is used to store the fetched data by defining a state variable whose initial value is an empty array. To start, first, import the hooks from the react library.
import React, { useState, useEffect } from 'react';
After that create a state variable called data inside the App component. Along with the data variable, define two other state variables, isLoading to track the whether app is in loading mode (that is, the data is being fetched from the API) and error to track if there is an error while fetching the data. The loading state of the React app is going to be true by default.
function App() { const [data, setData] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(''); //rest of the code }
The useEffect hook is going to have a callback that is going to fetch the data using JavaScript's fetch API.
useEffect(() => { fetch('https://randomuser.me/api/?results=5') .then(res => res.json()) .then( result => { setIsLoading(false); setData(result.results); }, error => { setIsLoading(false); setError(error); } ); }, []);
You can conditionally render the JSX based on the state variables.
if (isLoading) { return <div>Loading ...</div>; } else if (error) { return <div>There is an error fetching data.</div>; } else { return ( <div> <Navbar /> <List /> </div> ); }
Now, when you refresh the React app, you are going to see the JSX being rendered that is related to the loading state of the app, for split seconds.
Tumblr media
Display a list of users
You can now pass the user information you want to display in the form of the prop at the List component. Use JavaScript's map function to traverse the array data.
{ data.map(item => ( <List key={item.id.value} userAvatar={item.picture.large} firstName={item.name.first} lastName={item.name.last} /> )); }
These props are then passed as arguments to the List component.
xport default function List({ userAvatar, firstName, lastName }) { const classes = useStyles(); return ( <Grid container spacing={2}> <Grid item className={classes.root} xs={12}> <Grid container justify="center" spacing={2}> <Grid key={1} item> <Paper className={classes.paper} elevation={2}> <Grid container justify="center"> <Avatar alt="User" className={classes.avatarImage} src={userAvatar} /> <Typography variant="p"> Name: {firstName} {lastName} </Typography> </Grid> </Paper> </Grid> </Grid> </Grid> </Grid> ); }
The above code snippet uses few more core components from Material UI (such as Avatar). You can find their reference in the official documentation of this library. Here is the final result you are going to get when you back to the browser screen.
Tumblr media
Conclusion
I hope in this post, you get the idea of how you can leverage the core components of Material UI library in your React apps and save a ton of development time.
0 notes