2021년 7월 7일 수요일

How to Design Better Checkbox, Radio and Toggle Buttons?

 Selection controls allow users to complete tasks which involve making choices such as selecting options, switching settings on or off, or adding or removing items.

Sizes

Radio buttons

Checkboxes

Toggle Buttons

Mind the tap area

Colors and different states

Conclusion

rontend Coding Tips

1. Hiding an HTML element


<p hidden>This paragraph won't show up. It's hidden by HTML.</p>

2. Use the inset shorthand in CSS


div{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;

}
div{
position: absolute;
inset: 0;
}

 

3. Detect internet speed


navigator.connection.downlink;


4. Vibrate your phone


//vibrating the device for 500 millisecondswindow.navigator.vibrate(500);

5. Disable pull to refresh


body{
overscroll-behavior-y: contain;
}


6. Prevent the user from pasting text

<input type="text"></input><script>//selecting the input.
const input = document.querySelector('input');

//prevent the user to paste text by using the paste eventListener.
input.addEventListener("paste", function(e){
e.preventDefault()
})


</script>

2021년 6월 21일 월요일

Top Laravel Eloquent Features You May Not Know.

 

1. Check if Model changed

2. Get original attributes

3. Get changed attributes

Note: Here you need to keep in mind that, you will only get changes back if you save it or sync the changes with syncChanges()

4. Custom deleted_at column

5. Save relationships and models

6. Reload fresh model

7. Reload existing model

8. Check if models are the same

9. Clone a model

10. Specify attributes in find() method

Finally…

2021년 4월 15일 목요일

promise.all(), promise.any(), promise.race(), promise.allsettled() 차이 설명 쉬운 예제

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        
        const prom1 = new Promise((resolve, reject) => {
            setTimeout(() => {
                // resolve('first promise resolved')
                reject('first promise rejected')
            }, Math.floor(Math.random() * 1000));
        });

        const prom2 = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('second promise resolved')
                // reject('second promise rejected')
            }, Math.floor(Math.random() * 1000));
        });

        const prom3 = new Promise((resolve, reject) => {
            setTimeout(() => {
                // resolve('third promise resolved')
                reject('third promise rejected')
            }, Math.floor(Math.random() * 1000));
        });

        // Promise.all()
        // 첫 번째 거부 된 Promise로 오류를 던진다...
        (async function() {
            try {
                const result = await Promise.all([prom1, prom2, prom3]);
                console.log(result);
            } catch (err) {
                console.log(err)
            }
        })();

        // Promise.race()
        // 새로고침을 계속하면 3개중 하나의 결과만 리턴해준다.
        // reject든 resolve든 간에...
        (async function() {
            try {
                const result = await Promise.race([prom1, prom2, prom3]);
                console.log(result);
            } catch (err) {
                console.log(err)
            }
        })();
        
        // Promise.any()
        // Promise.race() 는 reject되도 상관없지만 any() 는 resolve된것만 리턴. 새로고침하며 결과 확인
        // Promise 중 하나가 reject 되더라도 다른 Promise를 계속 해결할 것.
        // 모든 Promise가 reject된 경우에만 집계 오류가 발생
        (async function() {
            const result = await Promise.any([prom1, prom2, prom3]);
            console.log(result); // Prints “A”, “B” or “C”
        })();

        // Promise.allSettled()
        // 모든 Promise가 resolve되거나 reject된 후에 각 Promise의 결과를 설명하는 다양한 개체와 함께 해결하는 Promise를 return
        (async function() {
            try {
                const result = await Promise.allSettled([prom1, prom2, prom3]);
                console.log(result);
            } catch (err) {
                console.log(err)
            }
        })();
    </script>
</body>
</html>