Skip to content

Instantly share code, notes, and snippets.

@kolibril13
Last active May 18, 2023 14:21
Show Gist options
  • Save kolibril13/a825918d8333ceadc2a4e9b117aade97 to your computer and use it in GitHub Desktop.
Save kolibril13/a825918d8333ceadc2a4e9b117aade97 to your computer and use it in GitHub Desktop.
diff-viewer-widget
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import ipyreact\n",
"from traitlets import Bool,Unicode, signature_has_traits\n",
"\n",
"@signature_has_traits\n",
"class DiffViewerWidget(ipyreact.ReactWidget):\n",
" code_a = Unicode('Hello World').tag(sync=True)\n",
" code_b = Unicode('Hello New World').tag(sync=True)\n",
" split_view = Bool(True).tag(sync=True)\n",
" \n",
" _esm = \"\"\"\n",
" import React from 'react';\n",
" import ReactDiffViewer from 'react-diff-viewer';\n",
"\n",
" export default function App({ code_a, code_b, split_view }) {\n",
" return (\n",
" <div\n",
" style={{\n",
" position: \"relative\",\n",
" width: \"450px\",\n",
" }}\n",
" >\n",
" <ReactDiffViewer oldValue={code_a} newValue={code_b} splitView={split_view} />\n",
" </div>\n",
" );\n",
" }\n",
" \"\"\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d7677855c996484583eae74055246c64",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"DiffViewerWidget(code_a='Cats purr gently', code_b='Cats meow softly')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d = DiffViewerWidget(\n",
" code_a='Cats purr gently', \n",
" code_b='Cats meow softly' \n",
" )\n",
"d"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d.code_a = \"\"\"\n",
"Cats purr gently\n",
"\n",
"\"\"\""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment