|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en" dir="rtl"> |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <title>RTL Segment View - Basic</title> |
| 6 | + <meta |
| 7 | + name="viewport" |
| 8 | + content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" |
| 9 | + /> |
| 10 | + <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" /> |
| 11 | + <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" /> |
| 12 | + <script src="../../../../../scripts/testing/scripts.js"></script> |
| 13 | + <script nomodule src="../../../../../dist/ionic/ionic.js"></script> |
| 14 | + <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script> |
| 15 | + |
| 16 | + <style> |
| 17 | + ion-segment-view { |
| 18 | + height: 100px; |
| 19 | + |
| 20 | + margin-bottom: 20px; |
| 21 | + } |
| 22 | + |
| 23 | + ion-segment-content { |
| 24 | + display: flex; |
| 25 | + justify-content: center; |
| 26 | + align-items: center; |
| 27 | + } |
| 28 | + |
| 29 | + ion-segment-content:nth-of-type(3n + 1) { |
| 30 | + background: lightpink; |
| 31 | + } |
| 32 | + |
| 33 | + ion-segment-content:nth-of-type(3n + 2) { |
| 34 | + background: lightblue; |
| 35 | + } |
| 36 | + |
| 37 | + ion-segment-content:nth-of-type(3n + 3) { |
| 38 | + background: lightgreen; |
| 39 | + } |
| 40 | + </style> |
| 41 | + </head> |
| 42 | + |
| 43 | + <body> |
| 44 | + <ion-app> |
| 45 | + <ion-header> |
| 46 | + <ion-toolbar> |
| 47 | + <ion-title>RTL Segment View - Basic</ion-title> |
| 48 | + </ion-toolbar> |
| 49 | + </ion-header> |
| 50 | + |
| 51 | + <ion-content> |
| 52 | + <ion-segment id="noValueSegment"> |
| 53 | + <ion-segment-button content-id="no" value="no"> |
| 54 | + <ion-label>No</ion-label> |
| 55 | + </ion-segment-button> |
| 56 | + <ion-segment-button content-id="value" value="value"> |
| 57 | + <ion-label>Value</ion-label> |
| 58 | + </ion-segment-button> |
| 59 | + </ion-segment> |
| 60 | + <ion-segment-view id="noValueSegmentView"> |
| 61 | + <ion-segment-content id="no">No</ion-segment-content> |
| 62 | + <ion-segment-content id="value">Value</ion-segment-content> |
| 63 | + </ion-segment-view> |
| 64 | + |
| 65 | + <ion-segment value="free"> |
| 66 | + <ion-segment-button content-id="paid" value="paid"> |
| 67 | + <ion-label>Paid</ion-label> |
| 68 | + </ion-segment-button> |
| 69 | + <ion-segment-button style="min-width: 200px" content-id="free" value="free"> |
| 70 | + <ion-label>Free</ion-label> |
| 71 | + </ion-segment-button> |
| 72 | + <ion-segment-button content-id="top" value="top"> |
| 73 | + <ion-label>Top</ion-label> |
| 74 | + </ion-segment-button> |
| 75 | + </ion-segment> |
| 76 | + <ion-segment-view> |
| 77 | + <ion-segment-content id="paid">Paid</ion-segment-content> |
| 78 | + <ion-segment-content id="free">Free</ion-segment-content> |
| 79 | + <ion-segment-content id="top">Top</ion-segment-content> |
| 80 | + </ion-segment-view> |
| 81 | + |
| 82 | + <ion-segment value="peach" scrollable> |
| 83 | + <ion-segment-button content-id="orange" value="orange"> |
| 84 | + <ion-label>Orange</ion-label> |
| 85 | + </ion-segment-button> |
| 86 | + <ion-segment-button content-id="banana" value="banana"> |
| 87 | + <ion-label>Banana</ion-label> |
| 88 | + </ion-segment-button> |
| 89 | + <ion-segment-button content-id="pear" value="pear"> |
| 90 | + <ion-label>Pear</ion-label> |
| 91 | + </ion-segment-button> |
| 92 | + <ion-segment-button content-id="peach" value="peach"> |
| 93 | + <ion-label>Peach</ion-label> |
| 94 | + </ion-segment-button> |
| 95 | + <ion-segment-button content-id="grape" value="grape"> |
| 96 | + <ion-label>Grape</ion-label> |
| 97 | + </ion-segment-button> |
| 98 | + <ion-segment-button content-id="mango" value="mango"> |
| 99 | + <ion-label>Mango</ion-label> |
| 100 | + </ion-segment-button> |
| 101 | + <ion-segment-button content-id="apple" value="apple"> |
| 102 | + <ion-label>Apple</ion-label> |
| 103 | + </ion-segment-button> |
| 104 | + <ion-segment-button content-id="strawberry" value="strawberry"> |
| 105 | + <ion-label>Strawberry</ion-label> |
| 106 | + </ion-segment-button> |
| 107 | + <ion-segment-button content-id="cherry" value="cherry"> |
| 108 | + <ion-label>Cherry</ion-label> |
| 109 | + </ion-segment-button> |
| 110 | + </ion-segment> |
| 111 | + <ion-segment-view> |
| 112 | + <ion-segment-content id="orange">Orange</ion-segment-content> |
| 113 | + <ion-segment-content id="banana">Banana</ion-segment-content> |
| 114 | + <ion-segment-content id="pear">Pear</ion-segment-content> |
| 115 | + <ion-segment-content id="peach">Peach</ion-segment-content> |
| 116 | + <ion-segment-content id="grape">Grape</ion-segment-content> |
| 117 | + <ion-segment-content id="mango">Mango</ion-segment-content> |
| 118 | + <ion-segment-content id="apple">Apple</ion-segment-content> |
| 119 | + <ion-segment-content id="strawberry">Strawberry</ion-segment-content> |
| 120 | + <ion-segment-content id="cherry">Cherry</ion-segment-content> |
| 121 | + </ion-segment-view> |
| 122 | + |
| 123 | + <button class="expand" onClick="changeSegmentContent()">Change Segment Content</button> |
| 124 | + |
| 125 | + <button class="expand" onClick="clearSegmentValue()">Clear Segment Value</button> |
| 126 | + |
| 127 | + <button class="expand" onClick="addSegmentButtonAndContent()">Add New Segment Button & Content</button> |
| 128 | + </ion-content> |
| 129 | + |
| 130 | + <ion-footer> |
| 131 | + <ion-toolbar> |
| 132 | + <ion-title>Footer</ion-title> |
| 133 | + </ion-toolbar> |
| 134 | + </ion-footer> |
| 135 | + |
| 136 | + <script> |
| 137 | + function changeSegmentContent() { |
| 138 | + const segment = document.querySelector('#noValueSegment'); |
| 139 | + const segmentView = document.querySelector('#noValueSegmentView'); |
| 140 | + |
| 141 | + let currentValue = segment.value; |
| 142 | + |
| 143 | + if (currentValue === 'value') { |
| 144 | + currentValue = 'no'; |
| 145 | + } else { |
| 146 | + currentValue = 'value'; |
| 147 | + } |
| 148 | + |
| 149 | + segment.value = currentValue; |
| 150 | + } |
| 151 | + |
| 152 | + async function clearSegmentValue() { |
| 153 | + const segmentView = document.querySelector('#noValueSegmentView'); |
| 154 | + segmentView.setContent('no', false); |
| 155 | + |
| 156 | + // Set timeout to ensure the value is cleared after |
| 157 | + // the segment content is updated |
| 158 | + setTimeout(() => { |
| 159 | + const segment = document.querySelector('#noValueSegment'); |
| 160 | + segment.value = undefined; |
| 161 | + }); |
| 162 | + } |
| 163 | + |
| 164 | + async function addSegmentButtonAndContent() { |
| 165 | + const segment = document.querySelector('ion-segment'); |
| 166 | + const segmentView = document.querySelector('ion-segment-view'); |
| 167 | + |
| 168 | + const newButton = document.createElement('ion-segment-button'); |
| 169 | + const newId = `new-${Date.now()}`; |
| 170 | + newButton.setAttribute('content-id', newId); |
| 171 | + newButton.setAttribute('value', newId); |
| 172 | + newButton.innerHTML = '<ion-label>New Button</ion-label>'; |
| 173 | + |
| 174 | + segment.appendChild(newButton); |
| 175 | + |
| 176 | + setTimeout(() => { |
| 177 | + // Timeout to test waitForSegmentContent() in segment-button |
| 178 | + const newContent = document.createElement('ion-segment-content'); |
| 179 | + newContent.setAttribute('id', newId); |
| 180 | + newContent.innerHTML = 'New Content'; |
| 181 | + |
| 182 | + segmentView.appendChild(newContent); |
| 183 | + |
| 184 | + // Necessary timeout to ensure the value is set after the content is added. |
| 185 | + // Otherwise, the transition is unsuccessful and the content is not shown. |
| 186 | + setTimeout(() => { |
| 187 | + segment.setAttribute('value', newId); |
| 188 | + }, 200); |
| 189 | + }, 200); |
| 190 | + } |
| 191 | + </script> |
| 192 | + </ion-app> |
| 193 | + </body> |
| 194 | +</html> |
0 commit comments