Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TextHighlighter): Add TextHighlighter component - React #384

Merged
merged 9 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/react/TextHighlighter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
@license

Copyright IBM Corp. 2025

This source code is licensed under the Apache-2.0 license found in the
LICENSE file in the root directory of this source tree.
-->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@carbon-labs/react-text-highlighter stackblitz</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions examples/react/TextHighlighter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "carbon-labs-react-text-highlighter",
jeffchew marked this conversation as resolved.
Show resolved Hide resolved
jeffchew marked this conversation as resolved.
Show resolved Hide resolved
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@carbon/react": "^1.72.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@carbon-labs/react-text-highlighter": "latest",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@vitejs/plugin-react": "^4.2.1",
"sass": "~1.83.0",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
}
17 changes: 17 additions & 0 deletions examples/react/TextHighlighter/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @license
*
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import { TextHighlighter } from '@carbon-labs/react-text-highlighter/es/index';

function App() {
return <TextHighlighter />;
}

export default App;
9 changes: 9 additions & 0 deletions examples/react/TextHighlighter/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

@use '@carbon/react';
@use '@carbon-labs/react-text-highlighter/scss/text-highlighter';
19 changes: 19 additions & 0 deletions examples/react/TextHighlighter/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
*
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.tsx';
import './index.scss';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
10 changes: 10 additions & 0 deletions examples/react/TextHighlighter/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @license
*
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

/// <reference types="vite/client" />
25 changes: 25 additions & 0 deletions examples/react/TextHighlighter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions examples/react/TextHighlighter/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
16 changes: 16 additions & 0 deletions examples/react/TextHighlighter/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @license
*
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { ArgTypes, Canvas, Meta, Controls } from '@storybook/blocks';
import * as TextHighlighterStories from './TextHighlighter.stories';

<Meta isTemplate />

# TextHighlighter

- **Initiative owner(s):** Punnoose Wilson
- **Status:** Preview candidate
jeffchew marked this conversation as resolved.
Show resolved Hide resolved
- **Target library:** TBD
- **Target library maintainer(s) / PR Reviewer(s):** N/A
- **Support channel:** `#carbon-labs`

{/* <!-- START doctoc generated TOC please keep comment here to allow auto update --> */}
{/* <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> */}

> 💡 Check our
> [Stackblitz](https://stackblitz.com/github/carbon-design-system/carbon-labs/tree/main/examples/react/TextHighlighter)
> example implementation.

[![Edit carbon-labs](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/carbon-design-system/carbon-labs/tree/main/examples/react/TextHighlighter)

## Table of Contents

- [Overview](#overview)
- [Variants](#here-we-have-a-component-offering-3-variants)
- [Getting started](#getting-started)
- [Example usages](#example-usages)
- [Version comparison](#1-version-comparison)
- [Reference anotation](#2-reference-anotation)
- [Document versioning](#3-document-versioning)
- [Document highlighting with source](#4-document-highlighting-with-source)

{/* <!-- END doctoc generated TOC please keep comment here to allow auto update --> */}

## Overview

The text highlighter feature enhances user experience by improving readability, focus, and engagement with the content. This feature is especially beneficial in various contexts such as version comparison, commenting, documentation etc

***It’s crucial that we use HTML semantics appropriately to represent the text highlighters, as improper usage could lead to a negative user experience. We must ensure effective communication to users utilizing assistive technologies, necessitating careful control over the markup.***

### Here we have a component offering 3 variants:

- 1st variant - `<mark>` : This HTML element represents text which is marked or highlighted for reference or notation purposes.
- 2nd variant - `<ins>` : This HTML element represents a range of text that has been added to a document. (Comparison purpose)
- 3rd variant - `<del>` : This HTML element represents a range of text that has been deleted from a document. (Comparison purpose)

<Canvas of={TextHighlighterStories.Default} />

<Controls />

## Getting started

Here's a quick example to get you started.

```bash
yarn add @carbon/react
yarn add @carbon-labs/react-text-highlighter
```

### JS (via import)

```javascript
import { TextHighlighter } from '@carbon-labs/react-text-highlighter/es/index';

function App() {
return <TextHighlighter />;
}

export default App;
```

### SCSS

In your styles file import

```
@use '@carbon/react';
@use '@carbon-labs/react-text-highlighter/scss/text-highlighter';
```

## Example usages

Text highlighters add significant value by making content more interactive, engaging, and easier to manage and understand.

### **1. Version comparison**

<Canvas of={TextHighlighterStories.VersionComparison} />

### **2. Reference anotation**

<Canvas of={TextHighlighterStories.ReferenceAnotation} />

### **3. Document versioning**

<Canvas of={TextHighlighterStories.DocumentVersioning} />

### **4. Document highlighting with source**

<Canvas of={TextHighlighterStories.DocumentHighlightingWithSource} />
Loading
Loading