Skip to content

Instantly share code, notes, and snippets.

View EduardoAC's full-sized avatar

Eduardo Aparicio Cardenes EduardoAC

View GitHub Profile
@EduardoAC
EduardoAC / table-comparing-react-vue-dynamic-components.md
Created March 29, 2025 16:04
DEX: Dynamic components React HoC vs Vue.JS slots comparison -Comparing Vue.js and React Approaches
Feature Vue.js (Slots & Dynamic Component) React (Render Props, JSX, HOCs)
Customization Explicit via slots or dynamic components Implicit via JSX or render props
Flexibility Very flexible (structured slots) Flexible, but requires setup
Type Safety Maintains type integrity JSX elements can be mixed types
Performance Direct rendering, no extra function calls Render props and HOCs add slight overhead
Best For Deep component customization Conditional rendering inside components
@EduardoAC
EduardoAC / radiobuttongroup.reactAsHigherOrderComponent.tsx
Last active March 29, 2025 15:40
Using Higher-Order Components (HOCs) - A more advanced pattern in React is to wrap the RadioButtonGroup with an HOC that injects label customization logic
export function withCustomLabel(Component: ReactNode) {
return (props) => {
const modifiedOptions = props.optionList.map((option) => ({
...option,
label: <CustomElement labelText={option.label} />,
}));
return <Component {...props} optionList={modifiedOptions} />;
};
};
@EduardoAC
EduardoAC / radiobuttongroup.reactAsRenderProp.tsx
Last active March 29, 2025 15:39
Using Render Props - To explicitly define how the label is rendered, we can provide a render function as a prop
export function RadioButtonGroup({ optionList, renderLabel }: RadioButtonGroupProps) {
return (
<div className="radio-button-group">
{optionList.map((option) => (
<div
key={option.value}
disabled={option.disabled}
className={selected === type.value && 'option--active' || ''}
>
{option.icon && <span className={`icon-${option.icon}`} />}
@EduardoAC
EduardoAC / radiobuttongroup.reactNodeAsProp.tsx
Last active March 29, 2025 15:40
Using ReactNode as a Prop - The simplest way to customize the label is to pass a ReactNode (JSX element) instead of a string.
export function RadioButtonGroup({ optionList, selected }: RadioButtonGroupProps) {
return (
<div className="radio-button-group">
{optionList.map((option) => (
<div
key={option.value}
disabled={option.disabled}
className={selected === type.value && 'option--active' || ''}
>
{option.icon && <span className={`icon-${option.icon}`} />}
@EduardoAC
EduardoAC / RadioButtonGroup.slotComponent.vue
Last active March 29, 2025 15:38
Using a Slot - We use a slot inside the RadioButtonGroup, allowing the parent component to control how label is rendered.
<template>
<div class="radio-button-group">
<div
v-for="option in optionList"
:key="option.value"
:disabled="option.disabled"
:class="{ 'option--active': selected === type.value }"
>
<div v-if="type.icon" :class="type.icon" />
<slot :labelText="option.label">
@EduardoAC
EduardoAC / RadioButtonGroup.dynamicComponent.vue
Last active March 29, 2025 15:39
Using a Dynamic Component - This approach allows the label to be rendered as a dynamic component inside RadioButtonGroup.
<template>
<div class="radio-button-group">
<div
v-for="option in optionList"
:key="option.value"
:disabled="option.disabled"
:class="{ 'option--active': selected === type.value }"
>
<div v-if="option.icon" :class="option.icon" />
<component :is="option.label" />
@EduardoAC
EduardoAC / .zshrc
Created December 17, 2024 06:52 — forked from chrisnolet/.zshrc
Color-coded git branch for zsh prompt
autoload -Uz compinit && compinit
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
add-zsh-hook precmd vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats " %F{cyan}%c%u(%b)%f"
zstyle ':vcs_info:*' actionformats " %F{cyan}%c%u(%b)%f %a"
zstyle ':vcs_info:*' stagedstr "%F{green}"
@EduardoAC
EduardoAC / eventHandler.test.ts
Last active June 7, 2024 11:28
Chrome Extension - Site Page Review - Message Handler test using jest.mock to mock underlying handlers
/* eslint-disable @typescript-eslint/no-explicit-any */
import { MessageRate } from "../../types/message.types"
import { messageHandler } from "./eventHandler"
import { ratingMessageHandler } from "./onMessageHandlers/ratingMessageHandler"
jest.mock("./onMessageHandlers/ratingMessageHandler")
describe("messageHandler", () => {
const sendResponseMock = jest.fn()
@EduardoAC
EduardoAC / ratingMessageHandler.test.ts
Created June 7, 2024 11:00
Chrome extension - testing rating message handler using jest-chrome for Chrome API mocking
/* eslint-disable @typescript-eslint/no-explicit-any */
import { JestChrome } from "jest-chrome/types/jest-chrome"
import { ratingMessageHandler } from "./ratingMessageHandler"
import { MessageRate } from "../../../types/message.types"
describe("ratingMessageHandler", () => {
const sendResponseMock = jest.fn()
const jestChrome = chrome as any as JestChrome
beforeEach(() => {
@EduardoAC
EduardoAC / getRateFromCache.test.ts
Created June 7, 2024 10:49
Chrome extension - testing get rate from cache using jest-chrome for Chrome API mocking
/* eslint-disable @typescript-eslint/no-explicit-any */
import { JestChrome } from "jest-chrome/types/jest-chrome"
import { getRateFromCache } from "./getRateFromCache"
describe("getRateFromCache", () => {
const sendResponseMock = jest.fn()
const jestChrome = chrome as any as JestChrome
beforeEach(() => {
jest.clearAllMocks()