Skip to content

Add Slots API for component customization#101

Merged
Nowely merged 4 commits intonextfrom
slots
Nov 15, 2025
Merged

Add Slots API for component customization#101
Nowely merged 4 commits intonextfrom
slots

Conversation

@Nowely
Copy link
Owner

@Nowely Nowely commented Nov 15, 2025

Summary

This PR introduces a new Slots API that enables developers to customize internal components of MarkedInput with improved type safety and flexibility. The implementation follows the MUI slots pattern, providing a standardized way to override internal components and pass custom props to them.

Key Features

  • New slots prop - Override internal components (container, span) with custom components
  • New slotProps prop - Pass custom props to slot components with type safety
  • Data attributes support - Automatic camelCase to kebab-case conversion for data attributes
  • Enhanced test coverage - Comprehensive tests for contentEditable behavior and event handlers

What's New

  • Slots interface for defining which components can be customized
  • SlotProps interface for type-safe prop passing
  • DataAttributes utility type for automatic attribute transformation
  • New utilities: resolveSlot() and dataAttributes() helper functions
  • Storybook stories demonstrating slots usage patterns

Documentation

  • Updated README with Slots section and examples
  • Added Storybook stories (Slots.stories.tsx)
  • Full TypeScript JSDoc documentation

Breaking Changes

Before:

<MarkedInput ...>
  <div onKeyDown={handler} />
  <span className="custom" />
</MarkedInput>

After:

<MarkedInput
  slots={{ container: 'div', textSpan: 'span' }}
  slotProps={{
    container: { onKeyDown: handler },
    textSpan: { className: 'custom' },
  }}
/>

This update introduces a new Slots API, allowing users to customize internal components of MarkedInput through the `slots` and `slotProps` props. Key changes include:

- **Slots API**: Users can now replace default components (container and span) with custom components.
- **SlotProps**: Additional props can be passed to these components for enhanced styling and behavior.
- **Documentation**: Updated README and new stories demonstrating the usage of the Slots API.
- **TypeScript Support**: Improved type definitions for slots and slotProps.

This enhancement provides greater flexibility and control over the component structure.
- Simplified event handler syntax in README example.
- Enhanced table formatting in README for better clarity.
- Streamlined JSX return statements in EditableSpan component.
- Improved formatting in dataAttributes and resolveSlot utility functions.
- Cleaned up test cases for MarkedInput to enhance readability.
@vercel
Copy link

vercel bot commented Nov 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marked-input Ready Ready Preview Comment Nov 15, 2025 9:33pm

@Nowely Nowely changed the title Slots Add Slots API for component customization Nov 15, 2025
- Updated ConfiguredMarkedInput in Base.stories.tsx to pass event handlers through slotProps for better encapsulation and customization.
- Improved JSX structure for clarity and maintainability.
@Nowely Nowely merged commit 86bd9c7 into next Nov 15, 2025
7 checks passed
@Nowely Nowely deleted the slots branch November 15, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant