Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Best JavaScript is No Javascript

Best JavaScript is No Javascript

Radoslav Stankov

November 13, 2023
Tweet

More Decks by Radoslav Stankov

Other Decks in Technology

Transcript

  1. !

  2. Angry Building Architecture $ % Ruby on Rails & No

    JavaScript ' No custom CSS, use Tailwind ( Extensive e2e tests ) Focus on domain
  3. * How to avoid writing code checklist + reduce scope,

    by adjusting business requirement , use build-in feature of the browser - use feature from core platform - Next / React / Angular ... . use type system / move to logic backend 0 (only when I really have to) use 3rd party library (browser edition)
  4. * How to avoid writing code checklist + reduce scope,

    by adjusting business requirement , use build-in feature of the browser - use feature from core platform - Next / React / Angular ... . use type system / move to logic backend 0 (only when I really have to) use 3rd party library (browser edition)
  5. function MyButton() { const [isHovered, setIsHovered] = useState(false); const className

    = isHovered ? 'button button-hover' : 'button'; const onMouseEnter = () => setIsHovered(true); const onMouseLeave = () => setIsHovered(false); return ( <button className={className} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>Button</button> ); }
  6. <details> <summary>System Requirements</summary> <p> Requires a computer running an operating

    system. The computer must have some memory and ideally some kind of long-term storage. An input device as well as some form of output device is recommended. </p> </details>
  7. @media (max-width: 640px) { .table-component, .table-component thead, .table-component tbody, .table-component

    tfoot, .table-component tr { display: block; } .table-component tbody td { display: flex; } .table-component tbody td:not(.actions):before { content: attr(title); flex: 0 1 35%; display: block; white-space: nowrap; } }
  8. @media (max-width: 640px) { .table-component, .table-component thead, .table-component tbody, .table-component

    tfoot, .table-component tr { display: block; } .table-component tbody td { display: flex; } .table-component tbody td:not(.actions):before { content: attr(title); flex: 0 1 35%; display: block; white-space: nowrap; } }
  9. @media (max-width: 640px) { .table-component, .table-component thead, .table-component tbody, .table-component

    tfoot, .table-component tr { display: block; } .table-component tbody td { display: flex; } .table-component tbody td:not(.actions):before { content: attr(title); flex: 0 1 35%; display: block; white-space: nowrap; } }
  10. @media (max-width: 640px) { .table-component, .table-component thead, .table-component tbody, .table-component

    tfoot, .table-component tr { display: block; } .table-component tbody td { display: flex; } .table-component tbody td:not(.actions):before { content: attr(title); flex: 0 1 35%; display: block; white-space: nowrap; } }
  11. 1 Accessible 2 Mobile friendly 3 All batteries include ➡

    No extra code 5 Single date, no range 5 Style doesn't match our site <input type="date">
  12. 1 Accessible 2 Build-in backdrop 3 Auto handling of forms

    (example: auto-focus) 6 Stops scrolling of back page 7 Auto handle of ESC 8 Style as you wish 5 JavaScript to trigger the modal version 5 JavaScript need to close dialog when click backdrop <dialog>
  13. import { setEventListners } from './utils'; setEventListners(document, { '[data-dialog]:click': (e)

    => { document .getElementById(e.target.closest('[data-dialog]').dataset.dialog) ?.showModal(); }, 'dialog:click': (e) => { if (e.target.tagName === 'DIALOG') { e.target.close(); } }, });
  14. /* Tooltip base styles for any element with a title

    attribute */ [title] { position: relative; cursor: pointer; display: inline-block; } /* Hidden before hover */ [title]::before, [title]::after { visibility: hidden; opacity: 0; pointer-events: none; } /* Tooltip text styling */ [title]::after { content: attr(title); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-5px); white-space: nowrap; z-index: 10; padding: 8px; border-radius: 4px; background-color: black; color: white; text-align: center; font-size: 14px; line-height: 1.2; transition: opacity 0.3s, visibility 0.3s; } /* Tooltip arrow */ [title]::before { content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(5px); border-width: 5px; border-style: solid; border-color: black transparent transparent transparent; transition: opacity 0.3s, visibility 0.3s; } /* Show tooltip on hover */ [title]:hover::before, [title]:hover::after { visibility: visible; opacity: 1; }
  15. /* Tooltip base styles for any element with a title

    attribute */ [title] { position: relative; cursor: pointer; display: inline-block; } /* Hidden before hover */ [title]::before, [title]::after { visibility: hidden; opacity: 0; pointer-events: none; } /* Tooltip text styling */ [title]::after { content: attr(title); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-5px); white-space: nowrap; z-index: 10; padding: 8px; border-radius: 4px; background-color: black; color: white; text-align: center; font-size: 14px; line-height: 1.2; transition: opacity 0.3s, visibility 0.3s; } /* Tooltip arrow */ [title]::before { content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(5px); border-width: 5px; border-style: solid; border-color: black transparent transparent transparent; transition: opacity 0.3s, visibility 0.3s; } /* Show tooltip on hover */ [title]:hover::before, [title]:hover::after { visibility: visible; opacity: 1; } ... and the code fits on a slide 9
  16. /* Tooltip base styles for any element with a title

    attribute */ [title] { position: relative; cursor: pointer; display: inline-block; } /* Hidden before hover */ [title]::before, [title]::after { visibility: hidden; opacity: 0; pointer-events: none; } /* Tooltip text styling */ [title]::after { content: attr(title); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-5px); white-space: nowrap; z-index: 10; padding: 8px; border-radius: 4px; background-color: black; color: white; text-align: center; font-size: 14px; line-height: 1.2; transition: opacity 0.3s, visibility 0.3s; } /* Tooltip arrow */ [title]::before { content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(5px); border-width: 5px; border-style: solid; border-color: black transparent transparent transparent; transition: opacity 0.3s, visibility 0.3s; } /* Show tooltip on hover */ [title]:hover::before, [title]:hover::after { visibility: visible; opacity: 1; }
  17. /* Tooltip base styles for any element with a title

    attribute */ [title] { position: relative; cursor: pointer; display: inline-block; } /* Hidden before hover */ [title]::before, [title]::after { visibility: hidden; opacity: 0; pointer-events: none; } /* Tooltip text styling */ [title]::after { content: attr(title); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-5px);
  18. /* Tooltip base styles for any element with a title

    attribute */ [title] { position: relative; cursor: pointer; display: inline-block; } /* Hidden before hover */ [title]::before, [title]::after { visibility: hidden; opacity: 0; pointer-events: none; } /* Tooltip text styling */ [title]::after { content: attr(title); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-5px); white-space: nowrap;
  19. pointer-events: none; } /* Tooltip text styling */ [title]::after {

    content: attr(title); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-5px); white-space: nowrap; z-index: 10; padding: 8px; border-radius: 4px; background-color: black; color: white; text-align: center; font-size: 14px; line-height: 1.2; transition: opacity 0.3s, visibility 0.3s; } /* Tooltip arrow */ [title]::before {
  20. line-height: 1.2; transition: opacity 0.3s, visibility 0.3s; } /* Tooltip

    arrow */ [title]::before { content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(5px); border-width: 5px; border-style: solid; border-color: black transparent transparent transparent; transition: opacity 0.3s, visibility 0.3s; } /* Show tooltip on hover */ [title]:hover::before, [title]:hover::after { visibility: visible; opacity: 1; }