@instructure/ui-source-code-editor 11.0.1-snapshot-1 → 11.0.1-snapshot-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,200 +38,10 @@ Setting the correct language adds **syntax highlighting** and other helpful feat
38
38
 
39
39
  **Note:** In case you need support for additional languages, please contact us on [GitHub](https://github.com/instructure/instructure-ui)!
40
40
 
41
- - ```js
42
- const languages = {
43
- json: `{
44
- "name": "@instructure/ui-source-code-editor",
45
- "version": "8.24.2",
46
- "description": "A UI component library made by Instructure Inc.",
47
- "author": "Instructure, Inc. Engineering and Product Design",
48
- "module": "./es/index.js",
49
- "main": "./lib/index.js",
50
- "types": "./types/index.d.ts",
51
- "repository": {
52
- "type": "git",
53
- "url": "https://github.com/instructure/instructure-ui.git"
54
- },
55
- }`,
56
- javascript: `const fruit: string = "apple"
57
-
58
- const re = new RegExp('ab+c')
59
-
60
- function exampleMethod(props: Props) {
61
- return props ? props.value : null
62
- }
63
-
64
- /**
65
- * This is an example
66
- * @param {Object} props
67
- */
68
- const Example = () => {
69
- return (
70
- <View as="div" padding={'large'}>
71
- <Position
72
- renderTarget={<GoodComponent />}
73
- placement='end center'
74
- offsetX='20px'
75
- >
76
- <span style={{ padding: '8px', background: 'white' }}>
77
- Positioned content
78
- </span>
79
- </Position>
80
- </View>
81
- )
82
- }
83
-
84
- render(<Example />)`,
85
- html: `<!DOCTYPE html>
86
- <html lang="en">
87
- <head>
88
- <meta charset="UTF-8" />
89
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
90
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
91
- <title>Example app</title>
92
- </head>
93
- <body>
94
- <div id="app">
95
- <button onclick="myFunction()">Click me</button>
96
- </div>
97
-
98
- <script src="script.js"></script>
99
- </body>
100
- </html>`,
101
- css: `a {
102
- text-decoration: none;
103
-
104
- &:hover { text-decoration: underline; }
105
- }
106
-
107
- a:link, a:visited, a:hover, a:active {
108
- background-color: green;
109
- color: white;
110
- padding: 10px 25px;
111
- text-align: center;
112
- text-decoration: none;
113
- display: inline-block;
114
- }
115
-
116
- .centertext { text-align: center; }
117
-
118
- img { opacity: 0.5; filter: alpha(opacity=50); }`,
119
- markdown: `#### The quarterly results look great!
120
-
121
- > - Revenue was off the chart.
122
- > - Profits were higher than ever.
123
-
124
- *Everything* is going according to **plan**.
125
-
126
- ---
127
- type: example
128
- ---`,
129
- shell: `#!/bin/bash
130
-
131
- # example of using arguments to a script
132
- echo "My first name is $1"
133
- echo "My surname is $2"
134
- echo "Total number of arguments is $#"
135
-
136
- ________________________________________
137
-
138
- $ chmod a+x name.sh
139
- $ ./name.sh Hans-Wolfgang Loidl
140
- My first name is Hans-Wolfgang
141
- My surname is Loidl
142
- Total number of arguments is 2`,
143
- yml: `---
144
- doe: "a deer, a female deer"
145
- ray: "a drop of golden sun"
146
- pi: 3.14159
147
- xmas: true
148
- french-hens: 3
149
- calling-birds:
150
- - huey
151
- - dewey
152
- - louie
153
- - fred
154
- xmas-fifth-day:
155
- calling-birds: four
156
- french-hens: 3
157
- golden-rings: 5
158
- partridges:
159
- count: 1
160
- location: "a pear tree"
161
- turtle-doves: two`
162
- }
163
-
164
- const languageMap = {
165
- json: languages.json,
166
- js: languages.javascript,
167
- jsx: languages.javascript,
168
- javascript: languages.javascript,
169
- html: languages.html,
170
- css: languages.css,
171
- markdown: languages.markdown,
172
- sh: languages.shell,
173
- shell: languages.shell,
174
- bash: languages.shell,
175
- yml: languages.yml,
176
- yaml: languages.yml
177
- }
178
-
179
- class LanguageExamples extends React.Component {
180
- state = {
181
- currentLanguage: 'javascript',
182
- currentValue: languageMap.javascript
183
- }
184
-
185
- render() {
186
- const languageKeys = Object.keys(languageMap)
187
-
188
- return (
189
- <Flex alignItems="start">
190
- <Flex.Item>
191
- <RadioInputGroup
192
- name="languageOptions"
193
- value={this.state.currentLanguage}
194
- description="Language"
195
- onChange={(e, currentLanguage) => {
196
- this.setState({
197
- currentLanguage,
198
- currentValue: languageMap[currentLanguage]
199
- })
200
- }}
201
- >
202
- {languageKeys.map((language) => (
203
- <RadioInput key={language} label={language} value={language} />
204
- ))}
205
- </RadioInputGroup>
206
- </Flex.Item>
207
-
208
- <Flex.Item padding="0 0 0 large" shouldGrow shouldShrink>
209
- <FormField label="SourceCodeEditor with syntax highlight">
210
- <SourceCodeEditor
211
- label={`${this.state.currentLanguage} code editor`}
212
- language={this.state.currentLanguage}
213
- value={this.state.currentValue}
214
- onChange={(value) => {
215
- this.setState({
216
- currentValue: value
217
- })
218
- }}
219
- lineNumbers
220
- lineWrapping
221
- highlightActiveLine
222
- highlightActiveLineGutter
223
- />
224
- </FormField>
225
- </Flex.Item>
226
- </Flex>
227
- )
228
- }
229
- }
230
-
231
- render(<LanguageExamples />)
232
- ```
233
-
234
- - ```js
41
+ ```js
42
+ ---
43
+ type: example
44
+ ---
235
45
  const languages = {
236
46
  json: `{
237
47
  "name": "@instructure/ui-source-code-editor",
@@ -247,13 +57,13 @@ Setting the correct language adds **syntax highlighting** and other helpful feat
247
57
  },
248
58
  }`,
249
59
  javascript: `const fruit: string = "apple"
250
-
60
+
251
61
  const re = new RegExp('ab+c')
252
-
62
+
253
63
  function exampleMethod(props: Props) {
254
64
  return props ? props.value : null
255
65
  }
256
-
66
+
257
67
  /**
258
68
  * This is an example
259
69
  * @param {Object} props
@@ -273,7 +83,7 @@ Setting the correct language adds **syntax highlighting** and other helpful feat
273
83
  </View>
274
84
  )
275
85
  }
276
-
86
+
277
87
  render(<Example />)`,
278
88
 
279
89
  html: `<!DOCTYPE html>
@@ -288,16 +98,16 @@ Setting the correct language adds **syntax highlighting** and other helpful feat
288
98
  <div id="app">
289
99
  <button onclick="myFunction()">Click me</button>
290
100
  </div>
291
-
101
+
292
102
  <script src="script.js"></script>
293
103
  </body>
294
104
  </html>`,
295
105
  css: `a {
296
106
  text-decoration: none;
297
-
107
+
298
108
  &:hover { text-decoration: underline; }
299
109
  }
300
-
110
+
301
111
  a:link, a:visited, a:hover, a:active {
302
112
  background-color: green;
303
113
  color: white;
@@ -306,29 +116,29 @@ Setting the correct language adds **syntax highlighting** and other helpful feat
306
116
  text-decoration: none;
307
117
  display: inline-block;
308
118
  }
309
-
119
+
310
120
  .centertext { text-align: center; }
311
-
121
+
312
122
  img { opacity: 0.5; filter: alpha(opacity=50); }`,
313
123
  markdown: `#### The quarterly results look great!
314
-
124
+
315
125
  > - Revenue was off the chart.
316
126
  > - Profits were higher than ever.
317
-
127
+
318
128
  *Everything* is going according to **plan**.
319
-
129
+
320
130
  ---
321
131
  type: example
322
132
  ---`,
323
133
  shell: `#!/bin/bash
324
-
134
+
325
135
  # example of using arguments to a script
326
136
  echo "My first name is $1"
327
137
  echo "My surname is $2"
328
138
  echo "Total number of arguments is $#"
329
-
139
+
330
140
  ________________________________________
331
-
141
+
332
142
  $ chmod a+x name.sh
333
143
  $ ./name.sh Hans-Wolfgang Loidl
334
144
  My first name is Hans-Wolfgang
@@ -415,7 +225,7 @@ Setting the correct language adds **syntax highlighting** and other helpful feat
415
225
  }
416
226
 
417
227
  render(<LanguageExamples />)
418
- ```
228
+ ```
419
229
 
420
230
  ### Controlled mode
421
231
 
@@ -423,85 +233,13 @@ SourceCodeEditor works best as an uncontrolled component (with the `defaultValue
423
233
 
424
234
  We've implemented the "controlled" usage, but please let us know if you run into any performance issues or bugs.
425
235
 
426
- - ```js
427
- class ControlledExample extends React.Component {
428
- state = {
429
- value: `const fruit: string = "apple"
430
-
431
- function exampleMethod(props: Props) {
432
- return props ? props.value : null
433
- }`
434
- }
435
-
436
- textAreaRef = null
437
-
438
- render() {
439
- return (
440
- <View display="block" background="primary">
441
- <Flex alignItems="start">
442
- <Flex.Item shouldGrow shouldShrink padding="0 large 0 0">
443
- <FormField
444
- label="Controlled code editor"
445
- id="controlledCodeEditor"
446
- messages={[
447
- {
448
- type: 'hint',
449
- text: 'Type in the editor or set the value from the textarea.'
450
- }
451
- ]}
452
- >
453
- <SourceCodeEditor
454
- label="controlled code editor"
455
- value={this.state.value}
456
- onChange={(value) => {
457
- this.setState({ value })
458
- }}
459
- highlightActiveLine
460
- highlightActiveLineGutter
461
- lineWrapping
462
- lineNumbers
463
- foldGutter
464
- spellcheck
465
- />
466
- </FormField>
467
- </Flex.Item>
468
- <Flex.Item size="50%" padding="0 0 0 large">
469
- <FormFieldGroup
470
- description="Set value from the outside"
471
- name="setValue"
472
- >
473
- <TextArea
474
- label={
475
- <ScreenReaderContent>Change value</ScreenReaderContent>
476
- }
477
- textareaRef={(e) => {
478
- this.textAreaRef = e
479
- }}
480
- defaultValue={this.state.value}
481
- />
482
- <Button
483
- color="primary"
484
- onClick={() => {
485
- this.setState({ value: this.textAreaRef.value })
486
- }}
487
- >
488
- Update value
489
- </Button>
490
- </FormFieldGroup>
491
- </Flex.Item>
492
- </Flex>
493
- </View>
494
- )
495
- }
496
- }
497
-
498
- render(<ControlledExample />)
499
- ```
500
-
501
- - ```js
236
+ ```js
237
+ ---
238
+ type: example
239
+ ---
502
240
  const ControlledExample = () => {
503
241
  const [value, setValue] = useState(`const fruit: string = "apple"
504
-
242
+
505
243
  function exampleMethod(props: Props) {
506
244
  return props ? props.value : null
507
245
  }`)
@@ -564,7 +302,7 @@ We've implemented the "controlled" usage, but please let us know if you run into
564
302
  )
565
303
  }
566
304
  render(<ControlledExample />)
567
- ```
305
+ ```
568
306
 
569
307
  ### Editable and readOnly
570
308
 
@@ -573,53 +311,10 @@ The editability of the content can be set with the combination of the `editable`
573
311
  The `readOnly` prop works like a "preventDefault" and disables any interaction by the user or API calls (e.g. copy-paste).
574
312
  If the `editable` prop is set to `false`, the editor is also not focusable, and the `contenteditable="false"` is set on the content.
575
313
 
576
- - ```js
577
- class EditableExample extends React.Component {
578
- state = {
579
- editable: true,
580
- readOnly: false
581
- }
582
-
583
- render() {
584
- return (
585
- <View
586
- display="block"
587
- padding="medium medium small"
588
- background="primary"
589
- >
590
- <View display="block" margin="small none large">
591
- <FormFieldGroup description="Settings" rowSpacing="small">
592
- {['editable', 'readOnly'].map((prop) => (
593
- <Checkbox
594
- label={prop}
595
- key={prop}
596
- defaultChecked={this.state[prop]}
597
- onChange={() => {
598
- this.setState({ [prop]: !this.state[prop] })
599
- }}
600
- />
601
- ))}
602
- </FormFieldGroup>
603
- </View>
604
-
605
- <SourceCodeEditor
606
- label="editable code editor"
607
- language="jsx"
608
- editable={this.state.editable}
609
- readOnly={this.state.readOnly}
610
- defaultValue={`function example() {
611
- console.log('example')
612
- }`}
613
- />
614
- </View>
615
- )
616
- }
617
- }
618
-
619
- render(<EditableExample />)
620
- ```
621
-
622
- - ```js
314
+ ```js
315
+ ---
316
+ type: example
317
+ ---
623
318
  const EditableExample = () => {
624
319
  const [settings, setSettings] = useState({
625
320
  editable: true,
@@ -659,7 +354,7 @@ If the `editable` prop is set to `false`, the editor is also not focusable, and
659
354
  )
660
355
  }
661
356
  render(<EditableExample />)
662
- ```
357
+ ```
663
358
 
664
359
  ### Gutter settings
665
360
 
@@ -667,86 +362,10 @@ The `lineNumbers` prop displays the line numbers in the side gutter, and the `fo
667
362
 
668
363
  If any of these two props are active, the gutter is displayed, and the `highlightActiveLineGutter` highlights the active line in the gutter. (The `highlightActiveLine` prop highlights the line itself.)
669
364
 
670
- - ```js
671
- class GutterExample extends React.Component {
672
- state = {
673
- lineNumbers: true,
674
- foldGutter: true,
675
- highlightActiveLineGutter: true,
676
- highlightActiveLine: true
677
- }
678
-
679
- render() {
680
- return (
681
- <View
682
- display="block"
683
- padding="medium medium small"
684
- background="primary"
685
- >
686
- <View display="block" margin="small none large">
687
- <FormFieldGroup description="Settings" rowSpacing="small">
688
- {[
689
- 'lineNumbers',
690
- 'foldGutter',
691
- 'highlightActiveLineGutter',
692
- 'highlightActiveLine'
693
- ].map((prop) => (
694
- <Checkbox
695
- label={prop}
696
- key={prop}
697
- defaultChecked={this.state[prop]}
698
- onChange={() => {
699
- this.setState({ [prop]: !this.state[prop] })
700
- }}
701
- />
702
- ))}
703
- </FormFieldGroup>
704
- </View>
705
-
706
- <SourceCodeEditor
707
- label="gutter example"
708
- language="jsx"
709
- lineNumbers={this.state.lineNumbers}
710
- foldGutter={this.state.foldGutter}
711
- highlightActiveLineGutter={this.state.highlightActiveLineGutter}
712
- highlightActiveLine={this.state.highlightActiveLine}
713
- defaultValue={`const fruit: string = "apple"
714
-
715
- function exampleMethod(props: Props) {
716
- return props ? props.value : null
717
- }
718
-
719
- /**
720
- * This is an example
721
- * @param {Object} props
722
- */
723
- const Example = () => {
724
- return (
725
- <View as="div" padding={'large'}>
726
- <Position
727
- renderTarget={<GoodComponent />}
728
- placement='end center'
729
- offsetX='20px'
730
- >
731
- <span style={{ padding: '8px', background: 'white' }}>
732
- Positioned content
733
- </span>
734
- </Position>
735
- </View>
736
- )
737
- }
738
-
739
- render(<Example />)`}
740
- />
741
- </View>
742
- )
743
- }
744
- }
745
-
746
- render(<GutterExample />)
747
- ```
748
-
749
- - ```js
365
+ ```js
366
+ ---
367
+ type: example
368
+ ---
750
369
  const GutterExample = () => {
751
370
  const [settings, setSettings] = useState({
752
371
  lineNumbers: true,
@@ -788,11 +407,11 @@ If any of these two props are active, the gutter is displayed, and the `highligh
788
407
  highlightActiveLineGutter={settings.highlightActiveLineGutter}
789
408
  highlightActiveLine={settings.highlightActiveLine}
790
409
  defaultValue={`const fruit: string = "apple"
791
-
410
+
792
411
  function exampleMethod(props: Props) {
793
412
  return props ? props.value : null
794
413
  }
795
-
414
+
796
415
  /**
797
416
  * This is an example
798
417
  * @param {Object} props
@@ -812,14 +431,14 @@ If any of these two props are active, the gutter is displayed, and the `highligh
812
431
  </View>
813
432
  )
814
433
  }
815
-
434
+
816
435
  render(<Example />)`}
817
436
  />
818
437
  </View>
819
438
  )
820
439
  }
821
440
  render(<GutterExample />)
822
- ```
441
+ ```
823
442
 
824
443
  ### Indentation
825
444
 
@@ -843,118 +462,10 @@ The `indentUnitCount` prop should be a string consisting either entirely of spac
843
462
 
844
463
  Another useful feature is the `indentAll` public method on the `SourceCodeEditor` component that can be called anytime to trigger a re-indent on the content.
845
464
 
846
- - ```js
847
- class IndentExample extends React.Component {
848
- state = {
849
- indentWithTab: true,
850
- indentUnitCount: '2'
851
- }
852
-
853
- editor = null
854
-
855
- get indentUnit() {
856
- return Array(parseInt(this.state.indentUnitCount)).fill(' ').join('')
857
- }
858
-
859
- reIndent() {
860
- this.editor.indentAll()
861
- }
862
-
863
- indentCurrentSelection() {
864
- this.editor.indentCurrentSelection()
865
- }
866
-
867
- render() {
868
- return (
869
- <View
870
- display="block"
871
- padding="medium medium small"
872
- background="primary"
873
- >
874
- <View display="block" margin="small none large">
875
- <FormFieldGroup description="Settings">
876
- <Checkbox
877
- label="indentWithTab"
878
- defaultChecked={this.state.indentWithTab}
879
- onChange={() => {
880
- this.setState({ indentWithTab: !this.state.indentWithTab })
881
- }}
882
- />
883
- <RadioInputGroup
884
- name="indentUnitCount"
885
- value={this.state.indentUnitCount}
886
- description="indent space count"
887
- onChange={(e, indentUnitCount) => {
888
- this.setState({ indentUnitCount })
889
- this.reIndent()
890
- }}
891
- >
892
- {['2', '4', '8'].map((count) => (
893
- <RadioInput key={count} label={count} value={count} />
894
- ))}
895
- </RadioInputGroup>
896
- <Button
897
- onClick={() => {
898
- this.reIndent()
899
- }}
900
- >
901
- Re-indent code
902
- </Button>
903
- <Button
904
- onClick={() => {
905
- this.indentCurrentSelection()
906
- }}
907
- >
908
- Indent current selection
909
- </Button>
910
- </FormFieldGroup>
911
- </View>
912
-
913
- <SourceCodeEditor
914
- label="indent example"
915
- ref={(component) => {
916
- this.editor = component
917
- }}
918
- language="jsx"
919
- indentWithTab={this.state.indentWithTab}
920
- indentUnit={this.indentUnit}
921
- defaultValue={`const fruit: string = "apple"
922
-
923
- function exampleMethod(props: Props) {
924
- return props ? props.value : null
925
- }
926
-
927
- /**
928
- * This is an example
929
- * @param {Object} props
930
- */
931
- const Example = () => {
932
- return (
933
- <View as="div" padding={'large'}>
934
- <Position
935
- renderTarget={<GoodComponent />}
936
- placement='end center'
937
- offsetX='20px'
938
- >
939
- <span style={{ padding: '8px', background: 'white' }}>
940
- Positioned content
941
- </span>
942
- </Position>
943
- </View>
944
- )
945
- }
946
-
947
- render(<Example />)`}
948
- />
949
- </View>
950
- )
951
- }
952
- }
953
-
954
- render(<IndentExample />)
955
- ```
956
-
957
- - ```js
465
+ ```js
466
+ ---
467
+ type: example
468
+ ---
958
469
  const IndentExample = () => {
959
470
  const [indentWithTab, setIndentWithTab] = useState(true)
960
471
  const [indentUnitCount, setIndentUnitCount] = useState('2')
@@ -1011,11 +522,11 @@ Another useful feature is the `indentAll` public method on the `SourceCodeEditor
1011
522
  indentWithTab={indentWithTab}
1012
523
  indentUnit={indentUnit}
1013
524
  defaultValue={`const fruit: string = "apple"
1014
-
525
+
1015
526
  function exampleMethod(props: Props) {
1016
527
  return props ? props.value : null
1017
528
  }
1018
-
529
+
1019
530
  /**
1020
531
  * This is an example
1021
532
  * @param {Object} props
@@ -1035,7 +546,7 @@ Another useful feature is the `indentAll` public method on the `SourceCodeEditor
1035
546
  </View>
1036
547
  )
1037
548
  }
1038
-
549
+
1039
550
  render(<Example />)`}
1040
551
  />
1041
552
  </View>
@@ -1043,7 +554,7 @@ Another useful feature is the `indentAll` public method on the `SourceCodeEditor
1043
554
  }
1044
555
 
1045
556
  render(<IndentExample />)
1046
- ```
557
+ ```
1047
558
 
1048
559
  ### Direction
1049
560
 
@@ -1051,93 +562,10 @@ SourceCodeEditor is a bidirectional component. It will inherit the text-directio
1051
562
 
1052
563
  The `rtlMoveVisually` prop controls the cursor movement in RTL mode, whether it should be **visual** (pressing the left arrow moves the cursor left) or **logical** (pressing the left arrow moves to the next lower index in the string, which is visually right in RTL text).
1053
564
 
1054
- - ```js
1055
- class DirectionExample extends React.Component {
1056
- state = {
1057
- contextDir: 'unset',
1058
- editorDir: 'unset',
1059
- rtlMoveVisually: true
1060
- }
1061
-
1062
- render() {
1063
- return (
1064
- <InstUISettingsProvider
1065
- dir={
1066
- this.state.contextDir !== 'unset'
1067
- ? this.state.contextDir
1068
- : undefined
1069
- }
1070
- >
1071
- <View
1072
- display="block"
1073
- padding="medium medium small"
1074
- background="primary"
1075
- >
1076
- <View display="block" margin="small none large">
1077
- <FormFieldGroup
1078
- description="Settings"
1079
- layout="columns"
1080
- vAlign="top"
1081
- >
1082
- <RadioInputGroup
1083
- name="contextDir"
1084
- value={this.state.contextDir}
1085
- description="context direction"
1086
- onChange={(e, contextDir) => {
1087
- this.setState({ contextDir })
1088
- }}
1089
- >
1090
- {['unset', 'ltr', 'rtl'].map((dir) => (
1091
- <RadioInput key={dir} label={dir} value={dir} />
1092
- ))}
1093
- </RadioInputGroup>
1094
- <RadioInputGroup
1095
- name="editorDir"
1096
- value={this.state.editorDir}
1097
- description="editor direction"
1098
- onChange={(e, editorDir) => {
1099
- this.setState({ editorDir })
1100
- }}
1101
- >
1102
- {['unset', 'ltr', 'rtl'].map((dir) => (
1103
- <RadioInput key={dir} label={dir} value={dir} />
1104
- ))}
1105
- </RadioInputGroup>
1106
- <Checkbox
1107
- label="rtlMoveVisually"
1108
- defaultChecked={this.state.rtlMoveVisually}
1109
- onChange={() => {
1110
- this.setState({
1111
- rtlMoveVisually: !this.state.rtlMoveVisually
1112
- })
1113
- }}
1114
- />
1115
- </FormFieldGroup>
1116
- </View>
1117
-
1118
- <SourceCodeEditor
1119
- label="editable code editor"
1120
- language="jsx"
1121
- direction={
1122
- this.state.editorDir !== 'unset'
1123
- ? this.state.editorDir
1124
- : undefined
1125
- }
1126
- rtlMoveVisually={this.state.rtlMoveVisually}
1127
- defaultValue={`function directionExample(dir?: 'ltr' | 'rtl') {
1128
- console.log(dir)
1129
- }`}
1130
- />
1131
- </View>
1132
- </InstUISettingsProvider>
1133
- )
1134
- }
1135
- }
1136
-
1137
- render(<DirectionExample />)
1138
- ```
1139
-
1140
- - ```js
565
+ ```js
566
+ ---
567
+ type: example
568
+ ---
1141
569
  const DirectionExample = () => {
1142
570
  const [settings, setSettings] = useState({
1143
571
  contextDir: 'unset',
@@ -1220,7 +648,7 @@ The `rtlMoveVisually` prop controls the cursor movement in RTL mode, whether it
1220
648
  }
1221
649
 
1222
650
  render(<DirectionExample />)
1223
- ```
651
+ ```
1224
652
 
1225
653
  ### Focus management
1226
654
 
@@ -1230,60 +658,10 @@ The `autofocus` prop will automatically focus the editor on the initial render.
1230
658
 
1231
659
  You can also manually focus the editor with its public `focus` method (the `hasFocus` getter is also available).
1232
660
 
1233
- - ```js
1234
- class FocusExample extends React.Component {
1235
- state = {
1236
- indentWithTab: true,
1237
- indentUnitCount: '2'
1238
- }
1239
-
1240
- editor = null
1241
-
1242
- render() {
1243
- return (
1244
- <View
1245
- display="block"
1246
- padding="medium medium small"
1247
- background="primary"
1248
- >
1249
- <View display="block" margin="small none large">
1250
- <Button
1251
- onClick={() => {
1252
- console.log('manual focus')
1253
- this.editor.focus()
1254
- }}
1255
- >
1256
- Focus editor
1257
- </Button>
1258
- </View>
1259
-
1260
- <SourceCodeEditor
1261
- label="focus example"
1262
- ref={(component) => {
1263
- this.editor = component
1264
- }}
1265
- language="jsx"
1266
- onFocus={() => {
1267
- console.log('onFocus')
1268
- console.log({ hasFocus: this.editor.hasFocus })
1269
- }}
1270
- onBlur={() => {
1271
- console.log('onBlur')
1272
- console.log({ hasFocus: this.editor.hasFocus })
1273
- }}
1274
- defaultValue={`function exampleMethod(props: Props) {
1275
- return props ? props.value : null
1276
- }`}
1277
- />
1278
- </View>
1279
- )
1280
- }
1281
- }
1282
-
1283
- render(<FocusExample />)
1284
- ```
1285
-
1286
- - ```js
661
+ ```js
662
+ ---
663
+ type: example
664
+ ---
1287
665
  const FocusExample = () => {
1288
666
  const [indentWithTab, setIndentWithTab] = useState(true)
1289
667
  const [indentUnitCount, setIndentUnitCount] = useState('2')
@@ -1324,83 +702,16 @@ You can also manually focus the editor with its public `focus` method (the `hasF
1324
702
  }
1325
703
 
1326
704
  render(<FocusExample />)
1327
- ```
705
+ ```
1328
706
 
1329
707
  ### Attachment
1330
708
 
1331
709
  The `attachment` prop removes the top/bottom border-radius and margin of the editor, so it can be attached to the top or bottom of another element.
1332
710
 
1333
- - ```js
1334
- class AttachmentExample extends React.Component {
1335
- state = {
1336
- attachment: 'none'
1337
- }
1338
-
1339
- render() {
1340
- const viewProps = {
1341
- as: 'div',
1342
- background: 'primary-inverse',
1343
- padding: 'small'
1344
- }
1345
-
1346
- return (
1347
- <View
1348
- display="block"
1349
- padding="medium medium small"
1350
- background="primary"
1351
- >
1352
- <View display="block" margin="small none large">
1353
- <RadioInputGroup
1354
- name="attachmentExample"
1355
- value={this.state.attachment}
1356
- description="attachment"
1357
- onChange={(e, attachment) => {
1358
- this.setState({ attachment })
1359
- }}
1360
- >
1361
- {['none', 'top', 'bottom'].map((attachment) => (
1362
- <RadioInput
1363
- key={attachment}
1364
- label={attachment}
1365
- value={attachment}
1366
- />
1367
- ))}
1368
- </RadioInputGroup>
1369
- </View>
1370
-
1371
- {this.state.attachment === 'bottom' && (
1372
- <View {...viewProps}>
1373
- CodeEditor is attached to the bottom of this element
1374
- </View>
1375
- )}
1376
- <SourceCodeEditor
1377
- label="attachment example"
1378
- language="jsx"
1379
- attachment={
1380
- this.state.attachment === 'none'
1381
- ? undefined
1382
- : this.state.attachment
1383
- }
1384
- defaultValue={`const fruit: string = "apple"
1385
-
1386
- function exampleMethod(props: Props) {
1387
- return props ? props.value : null
1388
- }`}
1389
- />
1390
- {this.state.attachment === 'top' && (
1391
- <View {...viewProps}>
1392
- CodeEditor is attached to the top of this element
1393
- </View>
1394
- )}
1395
- </View>
1396
- )
1397
- }
1398
- }
1399
-
1400
- render(<AttachmentExample />)
1401
- ```
1402
-
1403
- - ```js
711
+ ```js
712
+ ---
713
+ type: example
714
+ ---
1404
715
  const AttachmentExample = () => {
1405
716
  const [attachment, setAttachment] = useState('none')
1406
717
 
@@ -1441,7 +752,7 @@ The `attachment` prop removes the top/bottom border-radius and margin of the edi
1441
752
  language="jsx"
1442
753
  attachment={attachment === 'none' ? undefined : attachment}
1443
754
  defaultValue={`const fruit: string = "apple"
1444
-
755
+
1445
756
  function exampleMethod(props: Props) {
1446
757
  return props ? props.value : null
1447
758
  }`}
@@ -1456,7 +767,7 @@ The `attachment` prop removes the top/bottom border-radius and margin of the edi
1456
767
  }
1457
768
 
1458
769
  render(<AttachmentExample />)
1459
- ```
770
+ ```
1460
771
 
1461
772
  ### Search
1462
773