Code Viewer
PRO실행 결과와 적용 코드를 함께 보여주는 코드 문서 컴포넌트입니다.
사용 가이드
#실행 결과와 소스를 보여주는 코드 문서용 컴포넌트입니다. 코드를 편집하는 에디터는 아닙니다.
미리보기와 코드
sy-code-render에 UI를, sy-code-script에 코드를 넣어 함께 보여줍니다.
코드만 표시
소스를 이스케이프한 텍스트로 전달하세요. 코드 전용 화면은 항상 펼쳐집니다.
- 강조와 공통 옵션
- 부모에서 표시 옵션을 설정하고
highlightLines에2,4-6처럼 강조할 줄을 지정합니다. - 펼침 상태
defaultExpanded는 초기 상태,expanded는 앱에서 제어할 현재 상태입니다.
예제
#기능별 예제
#18개 주제에서 필요한 기능을 선택하세요. 속성 설정, 메서드 호출, 이벤트 결과와 슬롯 구성을 실행 화면과 코드로 확인할 수 있습니다.
일치하는 기능이 없습니다.
API reference
#이름에 마우스를 올리거나 키보드로 선택하면 적용 코드를 확인할 수 있습니다. 터치 화면에서는 이름을 누르세요.
<sy-code-viewer>
Properties
| Attribute / Property | Type | Default | Description |
|---|---|---|---|
string | 'plaintext' | 소스 강조에 사용할 언어입니다. | |
boolean | false | Show line-number gutter. | |
boolean | true | Show the copy-to-clipboard button at top-right of the source panel. | |
boolean | false | 긴 코드 줄을 다음 줄로 감쌉니다. | |
string | '' | Max-height of the script (code panel) section. Accepts any CSS length (`"320px"`, `"40vh"`, …). The live UI section and the collapse trigger are unaffected — only the code panel scrolls past this value. Renamed from the previous `maxHeight` to make the scope (script-only, not viewer-total) explicit at the call site. | |
string | '' | Comma list of line numbers / ranges to emphasize. e.g. "3,5-7,12". 1-based. | |
boolean | undefined | 소스 영역의 현재 펼침 상태를 외부에서 제어합니다. | |
boolean | true | 처음 표시할 때 소스 영역을 펼칩니다. | |
boolean | true | When false, the trigger is hidden and the script section is forced expanded. | |
string | 'SOURCE' | Text in the toggle bar. |
Events
| Event | Detail | Description |
|---|---|---|
CustomEvent<{ expanded: boolean; source: 'user' | 'prop' }> | Fires whenever the viewer's expand state changes — by user click on the trigger or by the host updating the `expanded` prop. `source` distinguishes "user click" from "programmatic" for analytics consumers. | |
CustomEvent<{ language: string }> | Fires when the `language` prop changes. | |
CustomEvent<{ raw: string; lines: number[] }> | Fires when the `highlightLines` prop changes. Payload includes parsed line numbers. | |
CustomEvent<{ hasRender: boolean; hasScript: boolean }> | Fires once after the viewer's first render is complete. |
Slots
| Slot | Description |
|---|---|
| 컴포넌트의 본문 또는 자식 항목입니다. |
<sy-code-render>
Properties
| Attribute / Property | Type | Default | Description |
|---|---|---|---|
string | '' | Authored markup snapshot — captured at connectedCallback time before descendants hydrate. Read by paired `<sy-code-script>` to display the user's authored markup instead of the post-hydration runtime DOM. Mutable so the component can refresh it after user-driven mutations. |
Events
| Event | Detail | Description |
|---|---|---|
CustomEvent<{ html: string }> | Fires whenever the snapshot is refreshed (initial connection or a user-driven mutation that reaches the host's own child list). Paired `<sy-code-script>` listens to this event to re-render the code panel. |
<sy-code-script>
Events
| Event | Detail | Description |
|---|---|---|
CustomEvent<{ code: string; language: string }> | Fires after the rendered copy button writes the code to the clipboard successfully. (Past-tense name avoids the JS property collision with the `copy` method that other web standards reserve.) | |
CustomEvent<{ code: string; lineCount: number; language: string }> | Fires whenever the resolved code changes. | |
CustomEvent<{ line: number }> | Fires when a line number is clicked (when `showLineNumbers` on viewer). |